Reputation: 6081
I just started iOS development, and now I'm stuck. I have a table cell, where the user cann see data. Next to it, there are two buttons. One to delete, one to edit. The edit part is where I'm stuck. I have a label field. When the user clicks on the edit button a prompt should come where the user can type in data. I already found something to do it. But there's no save button and I don't know how I could then save the variable to an NSString
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Name der neuen Liste" message:@"" delegate:self cancelButtonTitle:@"Abbrechen" otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
I currently have this. lNow a prompt pops up, where I can write something, but not save. I just can press cancel afterwards. How do I work with user input in iOS? I don't want to use the label as an UITextField
since it has to be clickable to perform another action.
Upvotes: 0
Views: 813
Reputation: 1268
Try this:
- (void)noteInput
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"input"
message:@"input"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Save", nil];
[alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
[alertView show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 1)
{
UITextField *noteText = [alertView textFieldAtIndex:0];
NSString *note = noteText.text;
}
}
Upvotes: 1
Reputation: 4856
Try adding a Save
button in otherButtonTitles
. Then, in your UIAlertViewDelegate
:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
// Save button pressed
}
}
Upvotes: 1