2013-10-29 30 views
0

我有一個應用程序,我試圖移植到iOS 7.因爲iOS 7 UIAlertViews中不再有任何文本框。 (見here)我不得不訴諸於使用2 UIViews管理1 ViewController.我沒有使用nib文件,只是從代碼編程UI。在UITextView中沒有顯示輸入的文本

當應用程序啓動時,第二個UIView堆疊在第一個上面,它有一個UITextField接受用戶輸入。此代碼適用於iOS 7,但不適用於iOS 6設備。

在iOS 6設備中,當我點擊第二個UIView中的文本框時,出現鍵盤。但是,當我在文本框中輸入內容時,不會出現任何字符。我甚至試圖NSLog鍵盤輸入的字符,並得到NULL這意味着沒有文字輸入!

的代碼是主視圖控制器如下:

//View1 : UIView 
View1 *aView1; 
[aView1 initWithFrame:CGRectMake(20,40,280,200) title:promptMsg] 
[self.view addSubview:aView1]; 

的View1.m內部:

(id)initWithFrame:(CGRect) aRect title:(NSString*) promptStr{ 
self = [super initWithFrame:aRect]; 
UITextField *userField = [[UITextField alloc] initWithFrame:CGRectMake(x,y,a,b)]; 
[self addSubview:userField]; 

有哪位知道在iOS的7已經改變了 '允許' 這種行爲?它是iOS 7還是SDK中的錯誤?

+1

如果你只需要在你的警報視圖中的文本字段,你爲什麼不直接使用'UIAlertViewStylePlainTextInput'作爲視圖的'alertViewStyle'屬性(可用於iOS 5)和'textFieldAtIndex:'來自定義文本字段? – omz

+0

嗨,謝謝,我知道這一點,但我的舊代碼擴展了UIAlertView有多達3個文本框,所以我需要像一個視圖:) – gigasai

回答

0

的問題是在你的代碼,我沒有看到你設置任何文本,你只是分配例如低於參考: -

(id)initWithFrame:(CGRect) aRect title:(NSString*) promptStr{ 
self = [super initWithFrame:aRect]; 
UITextField *userField = [[UITextField alloc] initWithFrame:CGRectMake(x,y,a,b)]; 
[email protected]"yourText"; // here setting the text 
[self addSubview:userField]; 
} 
+0

嗨,我做了userField.text = @「somerandomtext」;但我仍然無法在我的iOS 6設備上打字。 – gigasai

+0

試試這段代碼並檢查UITextField * txtField = [[UITextField alloc] initWithFrame:CGRectMake(5.0f,6.0f,278.0f,32.0f)]; [txtField setPlaceholder:@「My placeholder」]; [txtField setFont:[UIFont systemFontOfSize:15.0]]; [txtField setBorderStyle:UITextBorderStyleRoundedRect]; [txtField setAutocorrectionType:UITextAutocorrectionTypeNo]; [txtField setAutocapitalizationType:UITextAutocapitalizationTypeNone]; [txtField setKeyboardType:UIKeyboardTypeEmailAddress]; [txtField setReturnKeyType:UIReturnKeyDone]; [txtField setClearButtonMode:UITextFieldViewModeWhileEditing]; –

+0

不幸的是,也沒有工作..謝謝。我可以看到佔位符文本,我的光標,但是當我輸入什麼都沒有進入文本字段。 – gigasai