2

I have a quite complicated view. What I basicly have is the following

enter image description here

You can see I have a vertical tableview. In each cell I have a horizontal tableview. What I want to do now is when I scroll one horizontal tableview, every other horizontal tableview should scroll also.

In my subClass of the vertical tableviewCell I have the following.

  for(HorizontalTableCell *cell in mainTable.subviews){
        if([cell isKindOfClass:[HorizontalTableCell class]]){
            for(UITableView *cellTable in cell.subviews){
                if([cellTable isKindOfClass:[UITableView class]]){
                    NSLog(@"cell table is table %@",cellTable);
                    [cellTable setContentOffset:CGPointMake(scrollView.contentOffset.x, 0) animated:NO];
                }
            }
        }
    }

But this is not working OK. Can anybody help me with this?

4

2 回答 2

4

您将需要使用滚动视图委托方法。我建议发布一个通知,然后像这样在单元格中提取它......

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"CellScrolledHorizontally" object:self.tableView];
}

然后在水平单元格中,您可以观察通知。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scrolled:) name:@"CellScrolledHorizontally" object:nil];

- (void)scrolled:(NSNotification *)notification 
{ 
    UITableView *notificationTableView = notification.object; 

    if (notificationTableView == self.tableView) 
        return; 

    [self.tableView setContentOffset:notificationTableView.contentOffset]; 
}

或者,使用UICollectionView.

于 2013-05-16T09:08:45.047 回答
0

你可以试试这个逻辑:

而不是Horizontal tableviews使用UIScrollView. 现在的基地是UITableView一个horizontal scrollviews。现在使用UIScrollview delegate事件处理方法。

虽然这不是解决方案,但您可以查看EASYTABLEVIEW

于 2013-05-16T09:22:00.387 回答