2012-11-05 142 views

回答

7

在Cocoa for Mac OS X中,您有下一個響應者鏈,您可以在其中向文本字段詢問下一個控件應該有哪些焦點。這是使文本字段之間的tab鍵工作的原因。但是由於iPhone沒有鍵盤,只能觸摸,這一概念在向Cocoa Touch過渡之後還沒有存活下來。

這可以反正很容易做到,有兩個假設:

所有「tabbable」 UITextFields在同一個父視圖。 他們的「tab-order」由標籤屬性定義。 假設這可以覆蓋textFieldShouldReturn:就象這樣:

-(BOOL)textFieldShouldReturn:(UITextField*)textField; 
{ 
NSInteger nextTag = textField.tag + 1; 
    // Try to find next responder 
UIResponder* nextResponder = [textField.superview viewWithTag:nextTag]; 
if (nextResponder) { 
    // Found next responder, so set it. 
    [nextResponder becomeFirstResponder]; 
} else { 
// Not found, so remove keyboard. 
    [textField resignFirstResponder]; 
} 
return NO; // We do not want UITextField to insert line-breaks. 
} 

添加一些更多的代碼,並假設可以忽略不計爲好。

3

在回調的下一個按鈕,使用Next按鈕,

[self.TextBox2 becomeFirstResponder]; 

簡單!

+0

我的意思是我在TextBox1的IBAction中選擇了什麼事件類型 –

相關問題