textFieldのnextをクリックして現在のtableViewの次のtextFieldを探して応答者になります

1655 ワード

使用時にtextFieldのtagをindexPath.rowの値+1に設定する必要があります
//       textField
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    //    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++;
        }
    }
    //           textField
    if ((indexN + 1) < subNumber) {
        [array[indexN++] becomeFirstResponder];
        return YES;
    }
    //   table cell   textField   
    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;
}

書くのも大変でした.のオリジナルですよ.