我刚开始 iOS 开发,现在卡住了。我有一个表格单元格,用户可以在其中查看数据。在它旁边,有两个按钮。一个要删除,一个要编辑。编辑部分是我卡住的地方。我有一个标签字段。当用户点击编辑按钮时,应该出现一个提示,用户可以在其中输入数据。我已经找到了可以做的事情。但是没有保存按钮,我不知道如何将变量保存到 NSString
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Name der neuen Liste" message:@"" delegate:self cancelButtonTitle:@"Abbrechen" otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
我现在有这个。 l现在弹出提示,可以写东西,但不能保存。之后我可以按取消。如何在 iOS 中处理用户输入?我不想将标签用作 UITextField
,因为它必须可点击才能执行其他操作。
最佳答案
试试这个:
- (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;
}
}
关于ios - 提示用户输入并存储数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20546156/