xcode tableview 滚动到位置
xcode tableview scroll to position
我尝试编写一个表格视图,其中每个单元格都包含自己的文本字段。当用户选择一个文本字段时,表格视图应该滚动,直到包含所选文本字段的单元格位于表格视图可见部分的顶部。我该怎么做?
在您的 cellForRowAtIndexPath 中,为每个文本字段添加标签,例如,
[[cell myTextField] setTag:[indexPath row]];
[[cell myTextField] setDelegate:self] ;
实现 UITextField 委托方法:
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:textField.tag inSection:0]
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES]
}
我尝试编写一个表格视图,其中每个单元格都包含自己的文本字段。当用户选择一个文本字段时,表格视图应该滚动,直到包含所选文本字段的单元格位于表格视图可见部分的顶部。我该怎么做?
在您的 cellForRowAtIndexPath 中,为每个文本字段添加标签,例如,
[[cell myTextField] setTag:[indexPath row]];
[[cell myTextField] setDelegate:self] ;
实现 UITextField 委托方法:
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:textField.tag inSection:0]
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES]
}