How should I properly format this code?

Posted by ct2k7 on Stack Overflow See other posts from Stack Overflow or by ct2k7
Published on 2010-04-07T22:30:30Z Indexed on 2010/04/07 22:33 UTC
Read the original article Hit count: 240

Filed under:

Hi, I've a small issue here. I am using an if statement with UIAlertView and I have two situations, both result in UIAlertViews. However, in one situation, I want to dismiss just the UIAlertView, the other, I want the UIAlertView to be dismissed and view to return to root view.

This code describes is:

if([serverOutput isEqualToString:@"login.true"]){   

[Alert dismissWithClickedButtonIndex:0 animated:YES];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

UIAlertView *success = [[UIAlertView alloc] initWithTitle:@"Success" message:@"The transaction was a success!"
                                                          delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[success show];
[success release];  

} else {

    UIAlertView *failure = [[UIAlertView alloc] initWithTitle:@"Failure" message:@"The transaction failed. Contact sales operator!"
                                                     delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
    [failure show];
    [failure release];
}
}

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

switch(buttonIndex) {
    case 0: {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
} 
}

So, in both cases, they follow the above action, but obviously, that's not what I want. Any ideas on what I do here?

© Stack Overflow or respective owner

Related posts about iphone