2014年3月6日 星期四

UIAlertView的慣用法

//UploadViewController.h

@interface UploadViewController : UIViewController <UIAlertViewDelegate>



//UploadViewController.m

- (IBAction)logoutPressed:(id)sender
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Logout" message:@"Are you sure you want to logout?" delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil];
    [alert show];
}

- (void)logout
{
    //TODO:Implement Logout code here...
}


#pragma mark - UIAlertView Delegate

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == alertView.firstOtherButtonIndex) {
        [self logout];
    }

}

沒有留言:

張貼留言