【发布时间】:2017-01-10 05:23:53
【问题描述】:
我是 iOS 新手,我遇到了关于自动滚动表格视图单元格的问题。 我正在使用这样的代码
- (void)viewDidAppear:(BOOL)animated{
[table setContentOffset:CGPointMake(0.0, table.contentSize.height - table.bounds.size.height)
animated:YES];
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[headarray count]-1 inSection:0]
atScrollPosition:UITableViewScrollPositionBottom
animated:YES];
}
但它向我展示了我在这段代码中做错了什么。在此先感谢!
我在 connectionDidFinishLoading 方法中尝试了这样的代码
if ([headarray count] != 0) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[headarray count]-1 inSection:0];
[Newstable scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];
}
【问题讨论】:
-
您的代码绝对正确,但请检查此
[musicGenre count]-1 inSection:0],它返回的内容,检查其值和类。 -
@muja 试试我的代码,然后删除你的 [table setContentOffset:CGPointMake(0.0, table.contentSize.height - table.bounds.size.height) animated:YES];这一行
-
@Muju 你想像聊天一样滚动到表格的最后一行吗?
-
你的数据源数组是哪个?
headarray或musicGenre? -
@PiyushPatel Head 数组是我的数据源数组。
标签: ios objective-c uitableview uiscrollview