ios中提示框的使用

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

                       

旧版提示框

UIAlertView *alt=[[UIAlertView alloc]initWithTitle:@"友情提示" message:@"是否是成年人" delegate:self cancelButtonTitle:@"不满足" otherButtonTitles:@"满足", nil];    alt.delegate=self;    [alt show];
   
   
  • 1
  • 2
  • 3
  • 4

UIAlertView获取按钮的点击事件需要使用代理的方式,代理类为:UIAlertViewDelegate。然后实现其方法,即可获取按钮的点击事件。

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{    NSLog(@"%ld",buttonIndex);}
   
   
  • 1
  • 2
  • 3

底部提示框

UIActionSheet *sheet=[[UIActionSheet alloc] initWithTitle:@"请选择城市" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"北京" otherButtonTitles:@"上海", nil];    [sheet showInView:self.view];
   
   
  • 1
  • 2
  • 3

与上述提示框类似,代理为:UIActionSheetDelegate,点击的代理方法如下:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{}
   
   
  • 1
  • 2
  • 3

新版提示框

UIAlertController *controller=[UIAlertController alertControllerWithTitle:@"友情提示" message:@"是否购买" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *act1=[UIAlertAction actionWithTitle:@"买" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {    }];UIAlertAction *act2=[UIAlertAction actionWithTitle:@"不买" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {    }];    [controller addAction:act1];    [controller addAction:act2];    [self presentViewController:controller animated:YES completion:^{    }];
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

此提示框需要使用控件触发弹出。

新版ActionSheet

UIAlertController *controller=[UIAlertController alertControllerWithTitle:@"选择" message:@"请选择" preferredStyle:UIAlertControllerStyleActionSheet];    UIAlertAction *act1=[UIAlertAction actionWithTitle:@"买" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {    }];    UIAlertAction *act2=[UIAlertAction actionWithTitle:@"不买" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {    }];    [controller addAction:act1];    [controller addAction:act2];    [self presentViewController:controller animated:YES completion:^{    }];
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

取消提示框

[self dismissViewControllerAnimated:YES completion:^{    }];
   
   
  • 1
  • 2
  • 3
           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

这里写图片描述

猜你喜欢

转载自blog.csdn.net/qq_43685277/article/details/84035458