gpt4 book ai didi

iphone - 单击 UITableViewCell 中的 UITextField

转载 作者:太空狗 更新时间:2023-10-30 03:14:04 25 4
gpt4 key购买 nike

我遇到一个问题,当在 UITableViewCell 中单击 textField 时,方法 tableView:didSelectRowAtIndexPath: 不会被调用。问题是,我需要将我的 tableView 滚动到正确的位置,否则键盘会直接越过第一响应者。

然后我必须像这样移动代码:

[[self tableView] scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];

进入我的 tableView 委托(delegate)方法和我的 UITextField 委托(delegate)方法,textFieldDidBeginEditing:

最好的方法是创建一个新方法,将被单击的单元格/文本字段的 indexPath 传递给它,然后从 tableView 委托(delegate)和 UITextField 委托(delegate)中调用该方法吗?更好的方法?

最佳答案

我发现以下效果很好(假设您在 TableView Controller 中)

- (void)textFieldDidBeginEditing:(UITextField *)textField{  
CGPoint pnt = [self.tableView convertPoint:textField.bounds.origin fromView:textField];
NSIndexPath* path = [self.tableView indexPathForRowAtPoint:pnt];
[self.tableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionTop animated:YES];
}

关于iphone - 单击 UITableViewCell 中的 UITextField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/350868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com