gpt4 book ai didi

iPhone - 如何对称滚动两个 UITableViews

转载 作者:行者123 更新时间:2023-12-03 19:02:39 24 4
gpt4 key购买 nike

在我的应用程序中,我有两个并排的 tableView。当用户滚动时,我希望第二个同时滚动,因此它看起来几乎就像一个具有两个不同列的表。我有点不知道如何去做这件事,有什么建议吗?

谢谢,格雷格

最佳答案

方便地说,UITableView 是 UIScrollView 的子类。存在一个 UIScrollViewDelegate,它有这个方法:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

如果您实现该方法,则可以获得 scrollView 参数的 contentOffset 属性。那么,你应该使用

- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated

并设置新的内容偏移量。所以像这样:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
UIScrollView *otherScrollView = (scrollView == self.tableView1) ? self.tableView2 : self.tableView1;
[otherScrollView setContentOffset:[scrollView contentOffset] animated:NO];
}

如果您愿意,可以转换为 UITableView,但没有特殊理由这样做。

关于iPhone - 如何对称滚动两个 UITableViews,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6949142/

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