1
我已經在鍵盤上爲上一個/下一個/完成按鈕選擇的文本框創建了一個欄。這樣做時,我注意到我用於在文本字段之間導航的標籤發生了一個奇怪的事件。我正在用循環編程創建我的接口,因此,只需將標記值設置爲循環變量i即可。標籤標籤0的奇怪問題?
我在0開始i變量,所以創建的第一個文本字段的標籤爲零。基本上所發生的是'previous'按鈕的功能只會低到1.它甚至不會回到帶有0標籤的文本字段。解決此問題的唯一方法是將所有標記值增加1,以便第一個文本字段從1開始而不是零。
這是我的代碼。我的代碼中有一個錯誤,我看不到?或者這是一個奇怪的問題與標籤?
-(void)gotoPrevTextfield{
// If the active textfield is the first one, can't go to any previous
// field so just return.
UITextField *textField = (UITextField *)[inputsView viewWithTag:0];
NSLog(@"%i",textField.tag);
NSLog(@"%i",txtActiveField.tag);
if (txtActiveField == textField) {
NSLog(@"returning at previous");
return;
}
else {
NSLog(@"set responder");
// Otherwise if a different textfield has the focus, the operation
// of "previous" button can be done and set the previous as the first
// responder.
textField = (UITextField *)[inputsView viewWithTag:txtActiveField.tag - 1];
NSLog(@"%i",textField.tag);
NSLog(@"%i",txtActiveField.tag);
[textField becomeFirstResponder];
}
}
Aaah。這可能正是發生了什麼事。 – 2012-01-31 19:52:34
'enum'適用於建立名稱以表示一組接口項目的標籤。 @Jesse – 2012-01-31 20:10:48
@Josh Yep,特別是如果有幾種類型的標籤。 – zaph 2012-01-31 20:15:40