将两个UITableView一起滚动 [英] Scrolling two UITableViews together

查看:84
本文介绍了将两个UITableView一起滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的设计案例,我需要在同一个视图上放置两个UITableViews。我只想使用部分,但我需要在第二个表上使用索引。

I have a weird design case in which to implement I need to place two UITableViews on the same view. I would just use sections, but I need an index on the second table.

我希望它们一起滚动,就像它们实际上是同一个表的两个部分一样视图。这可能吗?

I'd like them to both scroll together like they were actually two sections of the same table view. Is this possible?

这是一个基本的模型,说明原因:

Here's a basic mockup illustrating why:

据我所知,你无法移动索引。此外,当您向表添加索引时,它会显示在整个tableview上,而不仅仅是一个部分。

As far as I understand it, you cannot move the index. Also, when you add an index to a table, it appears over the entire tableview, not just one section.

如果我必须将其作为两个表视图实现,两者都需要滚动就好像它们一样。如果可以使用部分来做到这一点,那就更好了。

If I have to implement this as two table views, they both need to scroll as if they were one. If it's possible to do this using sections, that's even better.

推荐答案

更新

在看到您的更新后,我的旧答案不是很好,但我会将其之前的答案留给其他想要它的人。

After seeing your update my old answer is not very good but I'll leave my previous answer for anyone else who wants it.

新答案 - 这取决于您希望表格同步的方式。

New answer - It depends how you want the tables sync'd.

如果您知道


  1. 哪些单元格位于前5

  2. 每个单元格的高度

  3. 表视图的偏移量

然后您可以计算顶部可见的单元格前5名表。您可以使用此信息将底部表格滚动到正确的索引。

Then you can calculate which cell is visible at the top of the top 5 table. You can use this information to scroll the bottom table to the correct index.

旧答案

我和其他人不确定你为什么会这么想或者我是否会误解,但这很简单。

I'm with the other guys not sure why you would want to or if I am misinterpreting but it's pretty simple.

UITableView UIScrollView 的子类,因此您可以将自己设置为 UITableViewDelegate 并覆盖

UITableView is a subclass of UIScrollView so you can set yourself as the UITableViewDelegate and override

- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
{
    UITableView *slaveTable = nil;

    if (self.table1 == scrollView) {
        slaveTable = self.table2;
    } else if (self.table2 == scrollView) {
        slaveTable = self.table1;
    }

    [slaveTable setContentOffset:scrollView.contentOffset];
}

这给我一些看起来像这样的东西:

This gives me something that looks like this:

顶部的 UITableView self.table1 ,底部是 self.table2 如果滚动任一表,则滚动在另一个表中镜像。

The top UITableView is self.table1 and the bottom is self.table2 if either table is scrolled the scrolling is mirrored in the other table.

这篇关于将两个UITableView一起滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆