iphone - 警报 View - 如何使用 clickedButtonAtIndex :

标签 iphone objective-c ios4 uialertview

我有这个警告 View (免责声明),它会在应用程序完成启动时弹出。它可以工作(我的应用程序现在慢得多),但如果用户按 no,thanks,我也想退出应用程序。我想我应该使用 clickedButtonAtIndex:.
1. 有人可以帮我解决这个问题吗?
2. viewDidLoad 是应用程序启动时触发 alertView 的最佳方法吗?
3. 有什么原因导致我的应用程序在构建和运行时需要更多时间才能启动?

-(void)viewDidLoad { 
    UIAlertView *disclaimer = [[UIAlertView alloc] initWithTitle:           @"DISCLAIMER" message:@"This Application is provided without any express or implied    warranty. Errors or omissions in either the software or the data are not guaranteed against. The application is not intented to replace official documentation or operational procedure. In no event shal the developer be held liable for any direct or indirect damages arising from the use of this application" delegate:self cancelButtonTitle:@"No, thanks" otherButtonTitles:@"Accept", nil];
    [disclaimer show];
    [disclaimer release];
    [super viewDidLoad];
}

最佳答案

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0)
// Do something
else
// Some code
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{

    if(buttonIndex == 0)
    // Do something
    else
    // Some code
}

确保您的类符合 UIAlertViewDelegate 协议(protocol)。

而且我认为退出应用程序不是一个好方法。您应该只让用户通过按主页按钮关闭应用程序。这违背了用户期望每个应用程序都遵循的默认行为。

关于iphone - 警报 View - 如何使用 clickedButtonAtIndex :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6199342/

相关文章:

iphone - 将字符串作为 JSON 对象发送

ios - 从其他类的 super View 中删除 View

objective-c - 为什么ARC转换将 "weak"装饰器添加到 "readonly"属性?

iphone - 调用已弃用的方法?

objective-c - CGContext 文本绘图不会在 iPhone 4 上按比例放大

ios - 当我在 xcode 上从 iPad 切换到 iPhone "view as"时,一个场景看起来仍然像 iPad

iphone - 如何捕获 iPhone 应用程序中的其他应用程序事件?

Objective-C 库 - 不能形成对类实例的弱引用

ios - oneDrive 下载文件的 URL 不接受 AccessToken

cocoa-touch - 标题未显示为 UIButton