Iphone 警报视图-如何使用ClickedButtonIndex:

Iphone 警报视图-如何使用ClickedButtonIndex:,iphone,objective-c,ios4,uialertview,Iphone,Objective C,Ios4,Uialertview,我有这个警报视图(免责声明),当应用程序启动完成时弹出。它可以工作(我的应用程序现在慢多了),但如果用户按否,我也想退出应用程序,谢谢。我想我应该使用ClickedButtonIndex:。 1.有人能帮我吗? 2.viewDidLoad是在应用程序启动时触发alertView的最佳方法吗? 3.现在我的应用程序在构建和运行时需要更多时间启动,有什么原因吗 -(void)viewDidLoad { UIAlertView *disclaimer = [[UIAlertView allo

我有这个警报视图(免责声明),当应用程序启动完成时弹出。它可以工作(我的应用程序现在慢多了),但如果用户按
否,我也想退出应用程序,谢谢。我想我应该使用ClickedButtonIndex:。
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];
}

确保您的类符合
UIAlertViewDelegate
协议

但是,我认为退出应用程序不是一个好方法。你应该只让用户按home按钮关闭应用程序。这与用户期望每个应用程序都遵循的默认行为背道而驰。

试试这个魔术:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(alertView.cancelButtonIndex == buttonIndex){
    // Do cancel
    }
    else{
    // Do the real thing
    }
}

我必须在何处插入此代码。。。。在}之前还是之后???我已经放置了委托,但在这种情况下,我不需要这样放置:disclaimer.delegate=self;???如果用户在}之后按“否,谢谢”,我需要使用哪种方法退出应用程序。请记住,这是一个单独的方法。:)
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{

    if(buttonIndex == 0)
    // Do something
    else
    // Some code
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(alertView.cancelButtonIndex == buttonIndex){
    // Do cancel
    }
    else{
    // Do the real thing
    }
}