如何从UIAlertView获取输入?

SST*_*SST 12 iphone cocoa objective-c uikit

我想通过使用UIAlertView将播放器名称作为输入.是否可以在UIAlertView上添加textField?

Tus*_*121 31

从iOS 5开始,UIAlertView提供了这个:将alertViewStyle属性更改为以下之一:

UIAlertViewStylePlainTextInput (1 text field)
UIAlertViewStyleSecureTextInput (1 password field)
UIAlertViewStyleLoginAndPasswordInput (both a text field and password field)
Run Code Online (Sandbox Code Playgroud)

然后使用textFieldAtIndex:获取所需的文本字段.这样,您甚至可以使用alertViewShouldEnableFirstOtherButton:委托方法来启用按钮.


Jim*_*vey 11

是的,这绝对是可能的,而且不是黑客攻击.您需要将UIAlertView子类化并将控件放入其中.因为它是一个子类,所以它将保持相同的外观和感觉等.

有关详细信息,请参阅Jeff LaMarche的本教程(来自Apress的Beginning iPhone Development的共同作者).