Show Alert Message snippet using UIAlertView

Use this when you just want to alert user without any callback for action

- (void) showAlert: (NSString *) title withMessage: (NSString *) message isRedText: (BOOL) isRedText withButton: (NSString *) btnText {
    // open a alert with an OK
    UIAlertView *alertView = [[UIAlertView alloc] init];
    [alertView setDelegate:nil];
    [alertView setTitle: title];
    [alertView setMessage: message];
    [alertView addButtonWithTitle: btnText];
    
    UILabel *theBody = [alertView valueForKey: @"_bodyTextLabel"];
    if (isRedText) {
        [theBody setTextColor:[UIColor redColor]];
    }
    
    [alertView show];

}

Notice that delegate of alertView is nil, if you want some callback when user press button, set delegate to self (or anything response for action), in .h file use this

<UIAlertViewDelegate>

Override this function:

- (void)alartView:(UIAlertView *)alertView clickedButtonAtindex:(NSInteger)buttonIndex
{
        [self release];
}

Comments

Popular posts from this blog

No visible @interface for class declares the selector

SFML - Lập trình game - Cài Đặt

IOS UniqueIdentifier in ios 7 (xCode 5)