简体   繁体   English

目标C-使UIAlertView等待用户输入吗?

[英]Objective C - Making UIAlertView wait for user input?

I have a UIAlertView set up with a textfield like so: 我有一个UIAlertView设置了像这样的文本字段:

//***first set of code***  
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"User Input Required" message:@"Please enter data into the field" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];  
    [alert addTextFieldWithValue:nil label:@"[Enter Text]"];  
    [[alert textField] becomeFirstResponder];  
    [alert show];  
    [alert release];  
//***second set of code***`

How can I make it so that the user is required to click a button (I have that method already set up to send the input to a string) BEFORE any of the 'second set of code' is fired off? 在任何“第二组代码”被触发之前,如何使用户需要单击按钮(我已经设置了该方法来将输入发送到字符串)?

I need that second set of code to be contained in the same section as the alert (so I can't just run it within the 'dismissWithClickedButtonIndex' method) and that second set of code is using the string obtained from the user input, so that is why I don't want that code to run prior to the user clicking a button. 我需要将第二组代码包含在与警报相同的部分中(所以我不能只在'dismissWithClickedButtonIndex'方法中运行它),而第二组代码使用的是从用户输入中获取的字符串,因此这就是为什么我不希望该代码在用户单击按钮之前运行。

Don't you just love it when people say "don't do it that way"... and then never give you any good/correct way you SHOULD be doing it. 当人们说“不要那样做”时,您不只是喜欢它吗……然后永远不要给您任何您应该做的好/正确的方式。

Thanks. 谢谢。

You can't do that. 你不能那样做。 show message in UIAlertView won't stop for user input. UIAlertView中的show消息不会停止供用户输入。 Associated delegates will need to handle the code you are planning to put in //***second set of code*** section. 关联的委托人将需要处理您打算放入//***second set of code***部分中//***second set of code***

Having said that, let me give you some advice. 话虽这么说,让我给你一些建议。 addTextFieldWithValue message is an undocumented API feature. addTextFieldWithValue消息是未记录的API功能。 Do not use it. 不要使用它。 It used to be a long time ago that approval process from Apple for you APP would let you pass even if your application used that addTextFieldWithValue message. 过去很久以前,即使您的应用程序使用了addTextFieldWithValue消息,Apple批准您的APP的审批流程仍会让您通过。 But nowadays that does not happen anymore. 但是如今,这种情况不再发生了。 Your application will be automatically rejected if it is using that undocumented feature. 如果您的应用程序使用的是未记录的功能,则该应用程序将自动被拒绝。 Here is a blog entry on the topic. 是有关该主题的博客条目。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM