【发布时间】:2026-02-10 00:00:01
【问题描述】:
我需要使用带有 textfield 的 uialertview 以便将输入的文本传递给 web 服务集成,而应用程序正在运行带有 textfield 的 alertview 显示并且可以在 textfield 中输入文本,但是在单击提交按钮时,相应的类已崩溃,但后退按钮和整个应用程序运行良好。
我用于带有文本字段的警报视图的代码,
{
//alertview with textfield
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Enter your changes"
message:nil
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Submit Changes", nil];
[message setAlertViewStyle:UIAlertViewStylePlainTextInput];
[message show];
}
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1)
{
text = [[alertView textFieldAtIndex:0] text];
NSLog(@"passed value %@",text);
}
}
【问题讨论】:
-
whre 完全崩溃了日志,我认为 text = [[alertView textFieldAtIndex:0] text];这条线崩溃了....什么是文本
-
@JitendraDeore,在没有添加 willdismisswithbuttonindex 的情况下使用 alertview 和 textfield 运行应用程序时,单击提交按钮显示相同的崩溃,因此 text = [[alertView textFieldAtIndex:0] text];我认为不会是这样
-
我通过运行它检查了你的代码..它永远不会崩溃......代码是完美的。错误可能在您的另一个代码中。
-
发布更多代码以了解问题
标签: ios uitextfield uialertview