我有分组的TableView用5段和类型为50个自定义细胞的总的自定义:的UITextField没有得到光标时的UITableView scrolles到不可见的细胞
Label | XXX
其中XXX可以的UITextField,UITextView的, UIButton,UILabel。单元格在tableView中有混合顺序。
要通过文本框的浏览& textViews我加入我的键盘上的下一个/上一个按钮。
问题是当我选择txtField和单击下一步或上一页按钮,表滚动到所需的细胞位置,但txtField没有得到光标。为了与文本框/的TextView得到小区i使用:
nextCell = [self tableView:_myTableView
cellForRowAtIndexPath:[NSIndexPath indexPathForRow:curRow inSection:curSec]];
我需要通过的tableView的所有细胞,不仅通过可见的人进行搜索。
正如我测试,问题是在这行代码,因为如果我打电话:
nextCell = [_myTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:curRow inSection:curSec]];
和所述细胞是可见的,则txtField得到光标。但是,如果我需要从单元格(section = 1,row = 6)跳转到不可见的单元格(section = 0,row = 3),我会得到nil。
我的按钮功能的全码:
-(void) previousTextField:(id)sender
{
int curTagInd = _editingTextElement.tag;
NSIndexPath *curInd = [self getRowIndexOf:_editingTextElement];
int curSec = curInd.section;
int curRow = curInd.row;
id nextView = nil;
UITableViewCell *nextCell = nil;
do {
curRow--;
if (curRow >=0) {
nextCell = [self tableView:_myTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:curRow inSection:curSec]];//[_myTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:--curRow inSection:curInd.section]];
curTagInd--;
if ([nextCell isKindOfClass:[CustomCell class]] || [nextCell isKindOfClass:[CustomLongTextCell class]]) {
do {
nextView = [nextCell viewWithTag:curTagInd];
if ([nextView isEnabled]) {
nextCell = nil;
_editingIndexPath = [NSIndexPath indexPathForRow:curRow inSection:curSec];
break;
}else{
break;
}
} while (nextView != nil && ((![nextView isKindOfClass:[UITextField class]] && ![nextView isKindOfClass:[UITextView class]]) || ![nextView isEnabled]));
}
}
else if(curSec > 0){ //got to previous section
curSec--;
curRow = [self getNumberOfRowsInSection:curSec];
curTagInd = [self getNumberOfRowsInSection:curSec]+1;
}
else{
nextCell = nil;
}
} while (nextCell != nil);
if (nextView != nil) {
[self.myTableView scrollToRowAtIndexPath:_editingIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
UITextField *textField = (UITextField *)nextView;
[textField becomeFirstResponder];
}
}
使用此代码我进去方法textFieldShouldBeginEditing:
,但不是在textFieldDidBeginEditing: