我正在 iOS 中构建一个聊天应用程序,但 UITableView 显示所有消息时遇到了一些问题。我希望表格视图在加载时滚动到底部,以便用户在打开应用程序时可以看到最新消息。
为此,我在刷新数据的函数中添加了以下代码:
NSIndexPath* ipath = [NSIndexPath indexPathForRow: [self.messageOnTimeline numberOfRowsInSection:0]-1 inSection: 0];
[self.messageOnTimeline scrollToRowAtIndexPath: ipath atScrollPosition: UITableViewScrollPositionTop animated: YES];
在我向 tableview 添加标题之前,这一直很好。我添加了以下代码,现在加载应用程序时它不会滚动到底部:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 30)];
return view;
}
有谁知道为什么?
非常感谢您的帮助