我正在编写一个具有分组 tableView 的应用程序,该 tableView 在模态转场中具有包含 UITextViews 的自定义单元格。我希望能够编辑每个单元格/ TextView 中的文本。我的问题是 ScrollView 底部的单元格/ TextView ,以便它们在键盘出现时出现在键盘上方。
根据评论中的要求编辑:prepareForSegue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"update info"]) {
UpdatesTableViewController *uvc = (UpdatesTableViewController *)segue.destinationViewController;
uvc.dumpInfo = self.dumpInfo;
}
}
如果我使用 UITableView Controller ,一切都很好——当 TextView 成为 firstResponder 时,每个单元格/ TextView 都会向上滚动到 View 的顶部,以便在编辑时可以看到它。但是当tableView滚动时,我添加到tableView顶部的导航栏会滚动。
如果我使用 UIViewController 并添加导航栏和表格 View ,我可以使用 UITableView scrollToRowAtIndexPath:atScrollPosition:animated: 方法让它向上滚动单元格。导航栏保持固定。但是底部的单元格无法向上滚动到足以显示的高度。
- (void)textViewDidBeginEditing:(UITextView *)textView
{
CGPoint location = [textView.superview convertPoint:textView.center toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition: UITableViewScrollPositionTop animated:YES];
}
UITableView Controller 正在施展一些很酷的魔法来完成这项工作——我想做的就是将导航栏固定在 View 顶部的位置。
最佳答案
您可以使用 UITableViewController
包装在 UINavigationController
中,如我的评论中所述。这将在屏幕上显示默认导航栏,并且不会与 tableview 一起滚动。 UITableViewController
需要设置为UINavigationController
的rootViewController。
由于您正面临崩溃,因为 [UINavigationController setDumpInfo:]: unrecognized selector sent to instance
,您需要将 prepareForSegue 方法更改为,
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"update info"]) {
UINavigationController *nav = (UINavigationController *)segue.destinationViewController;
UpdatesTableViewController *uvc = (UpdatesTableViewController *)nav.topViewController;
uvc.dumpInfo = self.dumpInfo;
}
}
在这种情况下,dumpInfo 基本上是在 navigationController
上调用的,而不是在您的 tableviewcontroller
上调用的。
关于ios - 具有自定义 UITextView 单元格的 TableView 将导航栏滚动到屏幕外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14150350/