在iOS9.0之前,使用彈出框的方法就是
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"警告框很簡(jiǎn)單" delegate:self cancelButtonTitle:@"確定" otherButtonTitles:@"按鈕一",@"按鈕二",@"按鈕三", nil];[alert show];
之后要具體實(shí)現(xiàn)點(diǎn)擊某一個(gè)按鈕時(shí)發(fā)生的事件,就要在代理方法里面寫。
-(void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
這是之前的方法,最新的方法不再使用UIAlertView,而是使用了UIAlertController。
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"注冊(cè)新用戶" message:nil preferredStyle:UIAlertControllerStyleAlert];
preferredStyle是設(shè)置提示框的類型,有兩種可以選擇
// 底部提示框
UIAlertControllerStyleActionSheet
// 中部提示框
UIAlertControllerStyleAlert
添加按鈕
[alert addAction:[UIAlertAction actionWithTitle:@"收藏" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]];
這種方法沒有代理方法,而是直接將點(diǎn)擊事件直接寫在添加按鈕后面的塊里面。這里的style也有三個(gè)可以選擇,根據(jù)自己需求選擇即可
UIAlertActionStyleDefault, //默認(rèn)
UIAlertActionStyleCancel, //取消
UIAlertActionStyleDestructive //警告
最后顯示出來就好啦
[self presentViewController:alert animated:YES completion:nil];