【问题标题】:UITableView can not scroll down. Keyboard is shown and not shown at the same timeUITableView 不能向下滚动。键盘同时显示和不显示
【发布时间】:2012-10-01 19:40:57
【问题描述】:
我有一个UITableView,它的UITableViewCells 可以通过tableView:heightForRowAtIndexPath 函数独立改变它们的大小。他们存储不同大小的UIImages。当我点击图像时,会显示键盘(假设它用于标记图像)。
如果我有 3 个单元格(图像),总高度比屏幕尺寸小于,这一切都很好。显示键盘,我可以滚动查看所有单元格(图像)。
但是当我再添加一个,将总尺寸推到大于屏幕时,一切都会中断。似乎显示了键盘(我在顶部有一个额外的按钮,使其比原来的键盘高一些像素,如图所示)。但是我什么都写不出来。键盘顶部的按钮是退出键盘,它不起作用。这有点卡住了。
项目可以在这里下载:https://github.com/TokyoBirdy/cecilia/tree/master/Test(请原谅乱码)
【问题讨论】:
标签:
uitableview
uiimageview
uitextview
【解决方案1】:
我能够通过删除编辑视图原点的代码来解决锁定滚动的问题。此外,我在计算中使用 tableview 的 contentSize 属性实现了滚动到底部单元格。
-(void) keyboardWillShow:(NSNotification *)note
{
if(!isKeyboardShowing)
{
isKeyboardShowing = YES;
CGRect keyboardBounds;
[[note.userInfo valueForKey:UIKeyboardBoundsUserInfoKey] getValue: &keyboardBounds];
CGFloat keyboardHeight = keyboardBounds.size.height;
CGRect frame = self.view.frame;
frame.size.height += keyboardHeight;
self.view.frame = frame;
CGPoint scrollPoint = frame.origin;
scrollPoint.y += _tableView.contentSize.height - keyboardHeight;
[_tableView setContentOffset:scrollPoint animated:YES];
}
}