我有分組的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: