为iOS应用程序开发对话框
AlertView
在iOS中开发一个对话框其实特别简单,在代码中加入如下代码就能实现弹出对话框效果,但是要注意的是别忘了释放对话框对象
//弹出对话框
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"新信息"
message:@"今天会有大雪哦"
delegate:nil
cancelButtonTitle:@"阅读"
otherButtonTitles:@"取消", nil];
//显示对话框
[alert show];
//清除对话框对象
[alert release];
就这样简单的一段代码就能实现如下效果
ActionSheet
第一步在ViewController.h文件中添加ActionSheet协议注意:<UIActionSheetDelegate>
@interface ViewController : UIViewController <UIActionSheetDelegate>{
IBOutlet UITextField *textField;
}
//显示SheetAlert控件
-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
//显示按钮的下标
NSLog(@"%i",buttonIndex);
}
第三步:在按钮的点击事件中调用协议中的弹出窗口方法,具体的方法格式如下:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"确定要删除数据吗?"
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:@"确定"
otherButtonTitles:nil, nil];
//注意显示改控件
[actionSheet showInView:self.view];
//在调用完改方法后,最后在方法中马上就销毁该对象
[actionSheet release];
最后的结果如下图中的内容很轻松就实现了