這裏是我的代碼,UITextField是在UIButton上單擊時以編程方式創建的。但是爲了增強,我想在創建UITextField時將焦點(並顯示鍵盤)設置爲新的UITextField。設置焦點並在xcode中以編程方式顯示鍵盤?
UITextField * txtComp=[[UITextField alloc]initWithFrame:CGRectMake(20,y, 450, 50)];
txtComp.borderStyle=UITextBorderStyleNone;
txtComp.delegate = self;
txtComp.tag=i+1;
txtComp.section=index;
txtComp.placeholder = @"New UITextField";
[txtComp becomeFirstResponder];
以上的編碼工作,創建新的UITextField,但不能將焦點設置新的UITextField即使becomeFirstResponder設置的。
我檢查你的代碼的工作在這裏很好,我覺得在txtcom.section =指標線的一些問題只是將其刪除,並檢查它 –
txtcom。 section = index用於分組,因此無法刪除。在我身邊,爲什麼鍵盤不能出現。 – ppshein
我已經使用你的代碼只是刪除該部分行,所以它會完美工作後點擊按鈕 –