2011-06-27 31 views

回答

3

從iOS 5開始,可以通過修改alertViewStyle屬性將文本字段或一對文本字段添加到UIAlertView

有用於alertViewStyle四種不同的選擇:

UIAlertViewStyleDefault = 0,   // No text fields 
UIAlertViewStyleSecureTextInput,  // A single text field with secure input 
UIAlertViewStylePlainTextInput,  // A single text field with plaintext input 
UIAlertViewStyleLoginAndPasswordInput // A pair of text fields, one with plaintext and one with a password 

要訪問的文本字段,你呼籲UIAlertView實例textFieldAtIndex:。根據該文件,指數開始0

遺產答案,的iOS 5.0之前:

如果您正在尋找呈現UIAlertView中有一個文本框,這不是在iOS的任何公共API支持,儘管你可以走視圖層次並添加自己的文本框。

或者,創建一個新的UIViewController子類並以模態方式呈現它。然後,您可以檢查視圖被解散時的值。

+0

工作...感謝很多.. –

+1

此答案無效!請考慮Tilo的答案(在UIAlertViewStyleLoginAndPasswordInput中使用'UIAlertView') –

+0

好的電話,感謝您的支持。 – Moshe

1

看看這個link,並添加用戶名,密碼字段到UIAlertView。

+0

多數民衆贊成在很好的教程..謝謝。 –

1

你也可以繼承UIAlertView中添加UITextFields它和像這樣定義一個指定初始化:

- (id)initWithTitle:(NSString *)title message:(NSString *)message 
delegate:(id)aDelegate 
cancelButtonTitle:(NSString*)cancelButtonTitle otherButtonTitle:(NSString*)otherButtonTitle { } 

這個方法裏面初始化文本框,並添加爲subView到您的視圖(子類UIAlertView中)。

希望它可以幫助你。