I require an input prompt in my app and I've tried this
// Create a new item
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"New item" message:@"Enter a name for the item" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
And then handling it like this:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
// The user created a new item, add it
if (buttonIndex == 1) {
// Get the input text
NSString *newItem = [[alertView textFieldAtIndex:0] text];
}
}
but it doesn't look like the clickedButtonAtIndex gets called, why?
Kind Regards, Erik
You need to set the delegate.
alert.delegate = self; //Or some other object other than self
Or when you initialise the alert:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"New item"
message:@"Enter a name for the item"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Add", nil];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With