gpt4 book ai didi

iphone - 在 UITableview 中自动向下和向上滚动

转载 作者:行者123 更新时间:2023-12-03 20:22:00 24 4
gpt4 key购买 nike

我正在开发一个Iphone应用程序,它包含一个带有8个单元格的UITableview。我实现了一个NSMutableArray,用于在单元格创建时间时存储每个单元格,但 TableView 加载时间仅向数组提供显示的单元格存储。为了避免这个问题我已经自动滚动 TableView 并使用以下代码获取要存储到数组的总单元格;

-(void)viewDidAppear:(BOOL)animated{

[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[musicGenre count]-1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];

}

这工作完美。但现在我想同时(加载时间)从下到上滚动它。如何实现这个?提前致谢。

最佳答案

由于 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];
}

编辑:

如果您希望从上到下的初始移动也具有动画效果,只需使用:

- (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];
}

但是请考虑用户体验 - 需要那么多动画吗?因为用户(特别是如果他们经常使用您的应用程序)不喜欢浪费时间。当动画能够增强用户体验并且不会导致工作流程延迟时,它就非常有用。

EDIT2:要滚动到顶部(从当前位置),您可以使用:

 [table setContentOffset:CGPointZero
animated:YES];

关于iphone - 在 UITableview 中自动向下和向上滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10960901/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com