日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)

發(fā)布時間:2025/6/15 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
本文轉(zhuǎn)載至?http://blog.csdn.net/liuwuguigui/article/details/39494597 IOS8UIAlertViewUIActionSheet

iOS8推出了幾個新的“controller”,主要是把類似之前的UIAlertView變成了UIAlertController,這不經(jīng)意的改變,貌似把我之前理解的“controller”一下子推翻了~但是也無所謂,有新東西不怕,學(xué)會使用了就行。接下來會探討一下這些個新的Controller。

?

- (void)showOkayCancelAlert {NSString *title = NSLocalizedString(@"A Short Title Is Best", nil);NSString *message = NSLocalizedString(@"A message should be a short, complete sentence.", nil);NSString *cancelButtonTitle = NSLocalizedString(@"Cancel", nil);NSString *otherButtonTitle = NSLocalizedString(@"OK", nil);UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];// Create the actions.UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {NSLog(@"The \"Okay/Cancel\" alert's cancel action occured.");}];UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {NSLog(@"The \"Okay/Cancel\" alert's other action occured.");}];// Add the actions.[alertController addAction:cancelAction];[alertController addAction:otherAction];[self presentViewController:alertController animated:YES completion:nil]; }

這是最普通的一個alertcontroller,一個取消按鈕,一個確定按鈕。

新的alertcontroller,其初始化方法也不一樣了,按鈕響應(yīng)方法綁定使用了block方式,有利有弊。需要注意的是不要因為block導(dǎo)致了引用循環(huán),記得使用__weak,尤其是使用到self。

上面的界面如下:

如果UIAlertAction *otherAction這種otherAction多幾個的話,它會自動排列成如下:

另外,很多時候,我們需要在alertcontroller中添加一個輸入框,例如輸入密碼:

這時候可以添加如下代碼:

[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {// 可以在這里對textfield進(jìn)行定制,例如改變背景色textField.backgroundColor = [UIColor orangeColor];}];

而改變背景色會這樣:

完整的密碼輸入:

- (void)showSecureTextEntryAlert {NSString *title = NSLocalizedString(@"A Short Title Is Best", nil);NSString *message = NSLocalizedString(@"A message should be a short, complete sentence.", nil);NSString *cancelButtonTitle = NSLocalizedString(@"Cancel", nil);NSString *otherButtonTitle = NSLocalizedString(@"OK", nil);UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];// Add the text field for the secure text entry.[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {// Listen for changes to the text field's text so that we can toggle the current// action's enabled property based on whether the user has entered a sufficiently// secure entry.[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleTextFieldTextDidChangeNotification:) name:UITextFieldTextDidChangeNotification object:textField];textField.secureTextEntry = YES;}];// Create the actions.UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {NSLog(@"The \"Secure Text Entry\" alert's cancel action occured.");// Stop listening for text changed notifications.[[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidChangeNotification object:alertController.textFields.firstObject];}];UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {NSLog(@"The \"Secure Text Entry\" alert's other action occured.");// Stop listening for text changed notifications.[[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidChangeNotification object:alertController.textFields.firstObject];}];// The text field initially has no text in the text field, so we'll disable it.otherAction.enabled = NO;// Hold onto the secure text alert action to toggle the enabled/disabled state when the text changed.self.secureTextAlertAction = otherAction;// Add the actions.[alertController addAction:cancelAction];[alertController addAction:otherAction];[self presentViewController:alertController animated:YES completion:nil]; }

注意四點:

1.添加通知,監(jiān)聽textfield內(nèi)容的改變:

// Add the text field for the secure text entry.[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {// Listen for changes to the text field's text so that we can toggle the current// action's enabled property based on whether the user has entered a sufficiently// secure entry.[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleTextFieldTextDidChangeNotification:) name:UITextFieldTextDidChangeNotification object:textField];textField.secureTextEntry = YES;}];

2.初始化時候,禁用“ok”按鈕:

otherAction.enabled = NO;

self.secureTextAlertAction = otherAction;//定義一個全局變量來存儲

3.當(dāng)輸入超過5個字符時候,使self.secureTextAlertAction = YES:

- (void)handleTextFieldTextDidChangeNotification:(NSNotification *)notification {UITextField *textField = notification.object;// Enforce a minimum length of >= 5 characters for secure text alerts.self.secureTextAlertAction.enabled = textField.text.length >= 5; }

4.在“OK”action中去掉通知:

UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {NSLog(@"The \"Secure Text Entry\" alert's other action occured.");// Stop listening for text changed notifications.[[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidChangeNotification object:alertController.textFields.firstObject];}];

?

最后是以前經(jīng)常是alertview與actionsheet結(jié)合使用,這里同樣也有:

- (void)showOkayCancelActionSheet {NSString *cancelButtonTitle = NSLocalizedString(@"Cancel", nil);NSString *destructiveButtonTitle = NSLocalizedString(@"OK", nil);UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];// Create the actions.UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {NSLog(@"The \"Okay/Cancel\" alert action sheet's cancel action occured.");}];UIAlertAction *destructiveAction = [UIAlertAction actionWithTitle:destructiveButtonTitle style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {NSLog(@"The \"Okay/Cancel\" alert action sheet's destructive action occured.");}];// Add the actions.[alertController addAction:cancelAction];[alertController addAction:destructiveAction];[self presentViewController:alertController animated:YES completion:nil]; }

在底部顯示如下:

?

好了,至此,基本就知道這個新的controller到底是怎樣使用了。

總結(jié)

以上是生活随笔為你收集整理的iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 黄色片视频免费 | 嫩草影院在线观看视频 | 亚洲+小说+欧美+激情+另类 | 欧美自拍色图 | 2020亚洲男人天堂 | 男女瑟瑟视频 | 久久久欧美 | 久久久不卡国产精品一区二区 | 91精品国产色综合久久不卡98 | 伊人春色网 | 最好看的2019中文大全在线观看 | 91看片看淫黄大片 | 亚洲国产成人久久 | 自拍偷拍亚洲一区 | 日本加勒比一区 | 全黄性性激高免费视频 | 男女视频免费网站 | 亚洲50p| 噜噜噜久久久 | 一区二区久久精品66国产精品 | 日本精品一区二区三区在线观看 | 日韩视频免费观看高清完整版 | 国产一级在线观看视频 | 美女写真福利视频 | 国产美女作爱全过程免费视频 | 狂野欧美性猛交xxxx777 | 亚洲AV无码成人精品区先锋 | 簧片av| 午夜操操 | 深夜av| 欧美成人乱码一区二区三区 | youjizzxxxxx | 精品一区二区三 | 亚洲欧美成人一区二区 | 4438亚洲 | 日韩亚洲精品中文字幕 | 狠狠操在线播放 | 亚洲乱码一区 | 久久久久99精品成人片三人毛片 | 日韩在线视频网址 | 黄色三级网站在线观看 | ass精品国模裸体欣赏pics | 色欲av无码一区二区三区 | 黑名单上的人全集免费观看 | 岛国av免费看 | 成人影视在线看 | 国内精品久久久 | 成人污视频 | 美女黄色免费网站 | 国产网站大全 | 久久精品国产77777蜜臀 | 亚洲黄色在线 | 91午夜影院 | 国产富婆一区二区三区 | 精品欧美一区二区精品少妇 | 亚洲不卡免费视频 | 国产乱淫a∨片免费观看 | 国产伦精品一区二区三区高清版 | 俺也去在线视频 | 97视频在线| 日本精品免费在线观看 | 久色国产 | 欧美黄色一区二区三区 | 视频在线播 | 狠狠做深爱婷婷久久综合一区 | 一级黄色片网站 | 亚洲乱人伦| 久久6| 穿情趣内衣被c到高潮视频 欧美性猛交xxxx黑人猛交 | 男人的天堂97 | www.avcao| 国产精品超碰 | 91精品在线看 | 男人天堂久久久 | 在线观看福利网站 | 欧美一级高清片 | 91成人亚洲| 免费黄色小网站 | 亚洲精品欧美激情 | 久久久久久欧美精品se一二三四 | 青青草在线视频免费观看 | 亚洲天堂一级 | 爱情岛论坛亚洲自拍 | 91久久国产综合久久91 | 男女做激情爱呻吟口述全过程 | 国产午夜电影在线观看 | 在线观看国产区 | 夜夜操天天 | 日日噜噜噜噜人人爽亚洲精品 | 久久色网站 | 亚洲国产一区二区三区在线观看 | 天天看黄色片 | 爱插美女网 | 国产内射一区 | 亚洲高清在线免费观看 | 国产青草 | 亚洲自拍偷拍第一页 | 奇米第四色首页 | 91综合视频 |