tim*_*iew 29 iphone uialertview ios ios5
更新UIAlertView现在有一个样式,允许在UIAlertViewie中的文本输入字段
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
这很好但我想用一个像"sample"这样的defualt文本初始化输入文本.
我看到过去的人们都使用过无证的api(效果很好)
[alert addTextFieldWithValue:@"sample text" label:@"Text Field"];
但由于这仍然不是官方的Apple公共API,我无法使用它.
还有其他办法吗?我确实尝试初始化,willPresentAlertView但文本字段似乎是只读的.
谢谢
Mut*_*tix 57
该UIALertView有一个textFieldAtIndex:返回的方法,UITextField你要的对象.
对于a UIAlertViewStylePlainTextInput,textfield的索引为0.
然后,您可以设置文本字段的占位符(或文本)属性:
UIAlertView *alert = ....
UITextField *textField = [alert textFieldAtIndex:0];
textField.placeholder = @"your text";
简单的方法
 UIAlertView *alerView = [[UIAlertView alloc] initWithTitle:@"your title" message:@"your message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
    alerView.alertViewStyle = UIAlertViewStylePlainTextInput;
    [[alerView textFieldAtIndex:0] setPlaceholder:@"placeholder text..."];
    [alerView show];
没有测试,但我认为这会工作:
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:...];
UITextField* textField = [alert textFieldAtIndex:0];
textField.text = @"sample";
[alert show];
要在uiAlertView中设置默认值,这个东西会起作用.
UIAlertView *alert = ....
UITextField *textField = [alert textFieldAtIndex:0];
[textField setText:@"My default text"];
[alert show];
| 归档时间: | 
 | 
| 查看次数: | 18000 次 | 
| 最近记录: |