UIAlertView的使用方法
轉載自:http://www.cnblogs.com/wljcan/archive/2011/08/12/2136611.html
UIAlertView類似于C#中的模態對話框 或 Messagebox ,但是,ios中使用起來要麻煩得多。
下面這段代碼是一段典型的應用:
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Message" message:@"Would you like to give us some advice?" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:@"Later", nil];[alertView show];[alertView release];??但是,如果復雜一點,就麻煩了,如果上面加上幾個按鈕,如:
?UIAlertView?*alert =[[UIAlertView?alloc]?initWithTitle:@"hello"?
?message:@"ipad ,i come"
? ? ??? ? ? ??delegate:self?
??? ? ? ? ???????cancelButtonTitle:@"ok"?
? ? ? ??otherButtonTitles:@"cancel",@"Ignore",nil?];
?
view 中會顯示3個按鈕,那怎么知道用戶選擇了哪個按鈕呢?
?
步驟如下:
1、在修改.h文件,添加對alertview的處理,如下:
@interface?pad4ViewController : UIViewController?<UIAlertViewDelegate>?{ .。。
2、在.m文件中添加對alertview事件的響應,如下: ?
-(void) alertView:(UIAlertView*)alertview?clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"%@",alertview.title);
}
?以上方法實現了當前.m中所有UIAlertView的事件響應,
alertview?指明是哪個 view,buttonIndex?指明是哪介按鈕。
轉載于:https://www.cnblogs.com/yang3wei/archive/2012/08/29/2739374.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的UIAlertView的使用方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ORA-16014 与 ORA-0031
- 下一篇: Windows完成端口的理解