您的位置:首页 > 其它

action sheet

2015-12-14 11:57 232 查看
#pragma mark - show  UIActionSheetDelegate
-(IBAction)shows:(id)sender{
UIActionSheet *alert = [[UIActionSheet alloc]initWithTitle:@"title" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"这是哪个button" otherButtonTitles:@"other1",@"other2", nil];
[alert showInView:self.view];
}
#pragma mark - UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
//获得当前索引按钮的标题
NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex];
NSLog(@"%@",title);

}


ios8.0 之后,用这个替换

#pragma mark - show
-(IBAction)shows:(id)sender{
//    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"My Title" message:@"show to you" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",@"Other", nil];
//    [alert show];

UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil  //nil  这一项就会隐藏
message:@"This is an alert." //nil  这一项就会隐藏
preferredStyle:UIAlertControllerStyleAlert];
//    typedef enum UIAlertControllerStyle: NSInteger {
//        UIAlertControllerStyleActionSheet = 0, //底端出现的  就是 UiActionSheet
//        UIAlertControllerStyleAlert            //对话框
//    } UIAlertControllerStyle;

UIAlertAction* OKAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
NSLog(@"%@",action.title);
}];
UIAlertAction* CancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
NSLog(@"%@",action.title);
}];
//addAction  添加
[alert addAction:OKAction];
[alert addAction:CancelAction];
[self presentViewController:alert animated:YES completion:nil];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: