나는 여러 UITableViewCells 가진 UITableView 있고 이러한 셀 안에 UITextFields 있습니다. 다른 텍스트 필드간에 전환하기 위해 UIToolbar를 구현했습니다. 다음 셀의 다음 텍스트 필드 나 이전 텍스트 필드로 이동할 수 있습니다. 셀이 테이블 뷰에서 현재 보이지 않는 첫 번째 응답자가 될 때까지이 작동합니다.UITableView scrollToRowAtIndexPath 경우에만 스크롤합니다
내가 알아 낸 그
[self.tableview cellForRowAtIndexPath:indexPath]
반환 nil
하고 수동으로 첫 번째로 반응이되어야 텍스트 필드와 셀, 스크롤, 문제를 제거합니다. 따라서 첫 번째 응답자가되도록 변경하기 전에 셀을 스크롤하려고했습니다.
[[self.tableView scrollToRowAtIndexPath:newIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
로하지만 불행히도있는 tableview이 셀에 다른 모든 세포로 이동하지 않습니다. 이 줄에 중단 점을 추가하면 문제가 발생하지 않습니다. 또한 테이블 뷰가 셀로 스크롤되지만 다시 아래로 스크롤되는 것처럼 보입니다. 이 도움이
UIView * currentResponder = [self.view findFirstResonder];
UITextField * newFocusTextField;
UITableViewCell * cell = (UITableViewCell*)[[currentResponder superview] superview];
NSIndexPath* indexPath = [self.tableView indexPathForCell:cell];
newFocusTextField = (UITextField*)[[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]] viewWithTag:1];
[currentResponder resignFirstResponder];
[newFocusTextField becomeFirstResponder];
UITableViewCell * newCell = (UITableViewCell*)[[newFocusTextField superview] superview];
NSIndexPath * newIndexPath = [self.tableView indexPathForCell:newCell];
[self.tableView scrollToRowAtIndexPath:newIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
희망 :
여기UITableViewCell *cell;
static NSString *AttributeCellIdentifier = @"AttributeCellIdentifier";
cell = [tableView dequeueReusableCellWithIdentifier:AttributeCellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"AttributeCell" owner:self options:nil];
cell = attributeCell;
self.attributeCell = nil;
UITextField * textField = (UITextField *)[cell viewWithTag:1];
[textField setKeyboardType:UIKeyboardTypeDecimalPad];
[textField setInputAccessoryView:[self inputAccessoryView]];
}
UITextField * textField;
textField = (UITextField *)[cell viewWithTag:1];
textField.placeholder = @"C(Probe)/mol/l";
return cell;
이전 텍스트 필드로 전환하기위한 코드입니다 : 여기
은 cellForRowAtIndexPath의 코드입니다.
cellForRowAtIndexPath에 대한 코드를 게시하십시오. 이 방법의 내용을 작성 했습니까? 그렇다면, 왜 그것을 돌려주지 않습니까?그렇지 않다면 왜 안 되겠습니까? – Rayfleck
나는 그 코드를 썼다. 그리고 스크롤이 작동하지 않을 때 셀이 보이지 않기 때문에 nil을 반환한다고 생각한다. cellForRowAtIndexPath에 대한 설명서에서 : 테이블의 셀을 나타내는 객체 또는 셀이 표시되지 않거나 indexPath가 범위를 벗어난 경우 nil. –
툴바를 탭하여 텍스트 필드를 노출/편집하면 어떻게됩니까? 여기에 순서 문제가 있는지 궁금합니다. 즉 셀을 먼저 노출 시키려면 표를 스크롤 한 다음 첫 번째 응답자로 만들어야합니다. – Rayfleck