我刚刚开始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
,因为必须点击该标签才能执行其他操作。
答案 0 :(得分:1)
尝试在Save
中添加otherButtonTitles
按钮。然后,在UIAlertViewDelegate
:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
// Save button pressed
}
}
答案 1 :(得分:1)
试试这个:
- (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;
}
}