0
在聯繫人應用程序的添加/編輯視圖中,如果您在字段中點擊「返回」鍵,則循環訪問每個UITextFields。這些字段似乎在UITableViewCell中。什麼是這樣做的好方法?在UITableViewCell內的UITextFields之間導航
當我有一系列不在表格內的UITextField時,我可以調用 [self.view viewWithTag:tag]
來獲取視圖列表以及循環使用的視圖。但是在一個表格中,我只能看到一個視圖,而我不知道如何將其轉換。
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
// Find the next entry field
for (UIView *view in [self entryFields]) {
if (view.tag == (textField.tag + 1)) {
[view becomeFirstResponder];
break;
}
}
return NO;
}
/*
Returns an array of all data entry fields in the view.
Fields are ordered by tag, and only fields with tag > 0 are included.
Returned fields are guaranteed to be a subclass of UIResponder.
From: http://iphoneincubator.com/blog/tag/uitextfield
*/
- (NSArray *)entryFields {
if (!entryFields) {
self.entryFields = [[NSMutableArray alloc] init];
NSInteger tag = 1;
UIView *aView;
while (aView = [self.view viewWithTag:tag]) {
if (aView && [[aView class] isSubclassOfClass:[UIResponder class]]) {
[entryFields addObject:aView];
}
tag++;
}
}
return entryFields;
}