UIAlertView input prompt
ios, objective-c, uialertview
Solution
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];
Problem
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