Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alert View - How to use clickedButtonAtIndex:

I have this alert view (disclaimer) that pop up when app finish launching. It works (my app is much slower now), but I also want to exit from the app if the user press no, thanks. I think I should use clickedButtonAtIndex:.
1. Can somebody help me on this?
2. is viewDidLoad the best method to fire the alertView when the application start?
3. is there any reason why now my app take more time to start when I build and run it?

-(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];
}
like image 545
Mat Avatar asked Nov 29 '22 04:11

Mat


2 Answers

Try this magic:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(alertView.cancelButtonIndex == buttonIndex){
    // Do cancel
    }
    else{
    // Do the real thing
    }
}
like image 36
malhal Avatar answered Dec 06 '22 02:12

malhal


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

or

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

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

Make sure your class conforms to the UIAlertViewDelegate protocol.

And I dont think exiting from the app is a good approach though.You should only let the user close the application by pressing the home button. It's against the default behavior which the user expects every app to follow.

like image 131
visakh7 Avatar answered Dec 06 '22 02:12

visakh7