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
推荐阅读
-
iOS使用 CABasicAnimation 实现简单的跑马灯(无cpu暴涨)
-
iOS使用核心动画和粒子发射器实现点赞按钮的方法
-
Android使用自定义控件HorizontalScrollView打造史上最简单的侧滑菜单
-
在WPF中使用Winform中自带的画图控件Chart,模拟动态更新数据
-
asp.net使用Repeater控件中的全选进行批量操作实例
-
iOS UISearchController的使用方法
-
IOS中MMDrawerController第三方抽屉效果的基本使用示例
-
iOS上下拉刷新控件MJRefresh使用方法详解
-
详解iOS使用Keychain中的kSecClassGenericPassword存储数据
-
IOS撤销键入这个影响摇一摇js的使用,如何用javascript禁止显示?