I am trying to add a new cell to a tableview and raise a warning using a UITextField to allow the user to enter the title that they want to pass to the new cell. I have code to display a warning using UITextField when the + button is pressed, and code to add a new cell, however, I don’t know how to get text from UITextField to insert it into the cell header.
This is my code to display a warning:
UIAlertView* alertPopUp = [[UIAlertView alloc] init];
[alertPopUp setDelegate:self];
[alertPopUp setTitle:@"Enter event title"];
[alertPopUp setMessage:@" "];
[alertPopUp addButtonWithTitle:@"Cancel"];
[alertPopUp addButtonWithTitle:@"OK"];
UITextField * eventNameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[eventNameField setBackgroundColor:[UIColor whiteColor]];
[alertPopUp addSubview:eventNameField];
[alertPopUp show];
and my alertView action:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *buttonTitle=[alertView buttonTitleAtIndex:buttonIndex];
if([buttonTitle isEqualToString:@"Cancel"]) {
return;
}
else if([buttonTitle isEqualToString:@"Ok"]) {
}
}
What can I do to get the text from eventNameField when the "Ok" button is clicked and add it to mutablearray named eventList? Thank!
source
share