IOS控件AlertView的使用
alert views are pop-up views that appear over the current view on the iphone.
creating and showing an alert (arc compatible):
uialertview *alert = [[uialertview alloc] initwithtitle:@"really reset?" message:@"do you really want to reset this game?" delegate:self cancelbuttontitle:@"cancel" otherbuttontitles:nil];
// optional - add more buttons:
[alert addbuttonwithtitle:@"yes"];
[alert show];
for non-arc (retain/release) projects, you must autorelease the alert view:
uialertview *alert = [[[uialertview alloc] initwithtitle:@"really reset?" message:@"do you really want to reset this game?" delegate:self cancelbuttontitle:@"cancel" otherbuttontitles:nil] autorelease];
// optional - add more buttons:
[alert addbuttonwithtitle:@"yes"];
[alert show];
if you add the uialertviewdelegate protocol to your controller, you can also add the following method which is called after the user dismisses the alert view:
- (void)alertview:(uialertview *)alertview diddismisswithbuttonindex:(nsinteger)buttonindex {
if (buttonindex == 1) {
// do stuff
}
}
button indices start at 0 (for the cancelbutton specified in the alloc/init), and go up by 1 for each addbuttonwithtitle call you add. if you have a lot of alerts, your diddismiss method can keep track of which one is being dismissed if you add the settag call to the alert initialization: [alert settag:23];
uialertview *alert = [[[uialertview alloc] initwithtitle:@"error" message:@"i'm sorry dave, i'm afraid i can't do that." delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil] autorelease];
[alert settag:12];
[alert show];
... later ...
- (void)alertview:(uialertview *)alertview diddismisswithbuttonindex:(nsinteger)buttonindex {
if ([alertview tag] == 12) { // it's the error alert
if (buttonindex == 0) { // and they clicked ok.
// do stuff
}
}
}
additional references
推荐阅读
-
EXTJS内使用ACTIVEX控件引起崩溃问题的解决方法_extjs
-
使用JS 清空File控件的路径值_javascript技巧
-
IOS AFNetworking的Post失败及requestSerializer的正确使用
-
iOS使用自带的UIViewController实现qq加号下拉菜单的功能(实例代码)
-
ASP.NET MVC中图表控件的使用方法
-
iOS开发--仿新闻首页效果WMPageController的使用详解
-
灵活掌握asp.net中gridview控件的多种使用方法(下)
-
iOS 中 使用UITextField格式化银行卡号码的解决方案
-
Android中shape定义控件的使用
-
C#使用RenderControl将GridView控件导出到EXCEL的方法