iOS engineer who likes clean, simple designs and sans-serif.

Loading

UIAlertView Plain Text Input (Example)

An example of UIAlertView to input data v7

1) Set up IBAction for button

- (IBAction)addAlbumBarButtonItemPressed:(UIBarButtonItem *)sender
{
    UIAlertView *newAlbumAlertView = [[UIAlertView alloc] initWithTitle:@"Enter New Album Name" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add", nil];
    [newAlbumAlertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
    [newAlbumAlertView show];
}

2) Conform to protocol in @implementation

3) Set up clickedButtonAtIndex method.

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {
        NSString *alertText = [alertView textFieldAtIndex:0].text;
        NSLog(@"My new album is %@", alertText);
    }
}

Leave a Comment