使用時需要設(shè)置textField的tag為indexPath.row的值+1
//自動跳轉(zhuǎn)下一個textField
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
//循環(huán)尋找TableViewCell
BOOL flag = YES;
UIView * object = textField;
do {
if ([object.superview isKindOfClass:[UITableViewCell class]]) {
flag = NO;
}
object = object.superview;
} while (flag);
//記錄textField的父視圖有幾個TextField以及當前是第幾個
int subNumber = 0, indexN = 0;
NSMutableArray *array = [NSMutableArray array];
for (id ob2 in object.subviews[0].subviews) {
if ([ob2 isKindOfClass:[UITextField class]]) {
[array insertObject:ob2 atIndex:0];
if ([NSStringFromCGRect(((UIView *)ob2).frame) isEqualToString:NSStringFromCGRect(textField.frame)]) {
indexN = subNumber;
}
subNumber++;
}
}
//跳轉(zhuǎn)當前父視圖的下一個textField
if ((indexN + 1) < subNumber) {
[array[indexN++] becomeFirstResponder];
return YES;
}
//在其他table的cell中尋找textField并跳轉(zhuǎn)
NSInteger maxNumber = [self.tableView numberOfRowsInSection:0];
for (int i = 0;i < maxNumber ; i++) {
//如果textField的tag等于row+1的話取余之前不用加1
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:(textField.tag + i) % maxNumber inSection:0]];
for (id ob2 in cell.subviews[0].subviews) {
if ([ob2 isKindOfClass:[UITextField class]]) {
[ob2 becomeFirstResponder];
return YES;
}
}
}
return YES;
}
寫的時候也挺費勁肠缨。往毡。原創(chuàng)哦。