IAlertView *alert =[[ UIAlertView alloc ] initWithTitle : @"hello"
message : @"ipad ,i come"
delegate : self
cancelButtonTitle : @"ok"
otherButtonTitles : nil ];
[alert show ];
[alert release ];
但是,如果復雜一點,就麻煩了,如果上面加上幾個按鈕,如:
UIAlertView *alert =[[ UIAlertView alloc ] initWithTitle : @"hello"
message : @"ipad ,i come"
delegate : self
cancelButtonTitle : @"ok"
otherButtonTitles :@ "cancel",@"Ignore",nil ];
view 中會顯示3個按鈕,那怎么知道用戶選擇了哪個按鈕呢?
步驟如下:
在.m文件中添加對alertview事件的響應,如下: - ( void ) alertView:( UIAlertView *)alertview
clickedButtonAtIndex:( NSInteger )buttonIndex{
if (buttonIndex== 0 )
{
NSLog ( @"%@" ,alertview. title );
}
}
如果此類中有多個 彈出框 那該如何區分是那個彈出框呢
利用tag
UIAlertView *errorDialogs= [[ UIAlertView alloc ] initWithTitle : @" 訂單創建失敗 " message: [ orderresult objectForKey: @"remark" ] delegate: self cancelButtonTitle : @" 返回 " otherButtonTitles : nil , nil ];
errorDialogs. tag = 3 ;
[errorDialogs show ];
[errorDialogs release ];
然后在判斷的時候這樣子
- ( void )alertView:( UIAlertView *)alertView clickedButtonAtIndex:( NSInteger )buttonIndex
{
if (buttonIndex== 0 ) {
if (alertView. tag == 3 )
{
//[ self . navigationController popViewControllerAnimated : YES ];
}
}
}
以上方法實現了當前.m中所有UIAlertView的事件響應, alertview 指明是哪個view, buttonIndex 指明是哪介按鈕。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
