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;
}