ios基础控件UIAlertView与UIActionSheet

来源:互联网 发布:mysql 有符号整型 编辑:程序博客网 时间:2024/06/16 20:53

1.UIAlertView

首先来看下UIAlertView的实现效果图:

第一步通过点击外部按钮弹出提醒对话框

- (IBAction)showAlertView:(id)sender {    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"标题" message:@"提醒内容" delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil];    [alert show];}


第二步实现对两个按钮点击事件的响应

#pragma mark - UIAlertViewDelegate- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{    NSLog(@"%ld", buttonIndex);}

2.UIActionSheet

首先来看下UIActionSheet实现的效果图



第一步给外部的按钮增加点击事件弹出操作表

- (IBAction)openActionSheet:(id)sender {    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"标题" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"破坏" otherButtonTitles:@"其它", nil];        [sheet showInView:self.view];}

第二步监听各个按钮点击事件

#pragma mark - UIActionSheetDelegate- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {    NSLog(@"%ld", buttonIndex);    NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex];    NSLog(@"您点击了:%@", title);}

注:以上两个控件在监听内部按钮点击响应事件时,都需要添加代理协议:

@interface OtherViewController ()<UIAlertViewDelegate, UIActionSheetDelegate>@end


0 0
原创粉丝点击