UIAlertView input request

I need to enter an input request in my application and I 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 process 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 a clickedButtonAtIndex call, why?

Regards, Erik

+7
ios objective-c uialertview
source share
2 answers

You need to install a delegate.

 alert.delegate = self; //Or some other object other than self 

Or when you initialize the warning:

 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"New item" message:@"Enter a name for the item" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add", nil]; 
+7
source share

The method is not called because you did not specify a delegate.
Pass yourself as a delegate so that he gets a link to him.

 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"New item" message:@"Enter a name for the item" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add", nil]; 
0
source share

All Articles