Joh*_*ohn 2 iphone objective-c uitableview
我正在开发一个Iphone应用程序,它包含一个带有8个单元格的UITableview.我实现了一个NSMutableArray,用于在单元格创建时存储每个单元格,但tableview加载时间只提供显示的单元格存储到数组.为避免这个问题我自动滚动表视图并使用以下代码获取存储到数组的总单元格;
-(void)viewDidAppear:(BOOL)animated{
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[musicGenre count]-1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
这是完美的工作.但是现在我想要同时从下到上滚动(加载时间).如何实现这个?提前致谢.
由于UITableView
继承自UIScrollView
你可以使用这样的东西:
- (void)viewDidAppear:(BOOL)animated{
[table setContentOffset:CGPointMake(0.0, table.contentSize.height - table.bounds.size.height)
animated:NO];
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[musicGenre count]-1 inSection:0]
atScrollPosition:UITableViewScrollPositionBottom
animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
编辑:
如果你想从顶部到底部的初始移动也动画,只需使用:
- (void)viewDidAppear:(BOOL)animated{
[table setContentOffset:CGPointMake(0.0, table.contentSize.height - table.bounds.size.height)
animated:YES];
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[musicGenre count]-1 inSection:0]
atScrollPosition:UITableViewScrollPositionBottom
animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
但请考虑用户体验 - 是否需要动画?因为用户(特别是如果他们经常使用你的应用程序)不喜欢浪费时间.动画在增强用户体验并且不会导致工作流延迟时非常出色.
EDIT2:滚动到顶部(从当前位置)您可以使用:
[table setContentOffset:CGPointZero
animated:YES];
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10179 次 |
最近记录: |