一个UIView中的2个UITableViews [英] 2 UITableViews in one UIView

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

问题描述

我有一个 UIView 需要显示两个UITableViews,但它们永远不会一起显示,使用 SegementedBar 你可以切换一个或另一个。

I have a UIView that will need to display two UITableViews, but they are never shown together, by using a SegementedBar you can toggle one or the other.

处理这个问题的最佳方法是什么?只需创建一个表视图控制器并更改数据源,或创建2 表视图控制器,然后只需隐藏一个其他是可见的。

What would be the best way to handle this? Just create one Table View Controller and change the data source, or create 2 Table View Controllers and just hide one when the other is visible.

2个表格将有一个完全不同的布局和不同的自定义单元格。

The 2 tables will have a completely different layout with different custom cells.

推荐答案

我会保留一个数据源&委托。

I would keep one datasource & delegate.

这意味着所有委托/数据源方法变得更加复杂但是这意味着你可以保持viewController和amp;之间的一对一关系。查看。

This means that all the delegate/datasource methods become more complicated BUT it means that you can retain the one to one relationship between viewController & view.

保留对每个表视图的引用

keep a reference to each of the table views

//vc.h
@property (nonatomic, weak) IBOutlet UITableView* firstTableView;
@property (nonatomic, weak) IBOutlet UITableView* secondTableView;

在数据源/委托方法中,您需要考虑到方法需要表现不同的事实。在哪个表视图中使用。例如

In the datasource/ delegate methods you need to account for the fact that the method needs to behave differently depending on which table view is in use. e.g.

//vc.m
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    ...

    if (tableView == self.firstTableView) {

        ...

    } else { // tableView == self.secondTableView

        ...
    }
}

return cell;

}

这篇关于一个UIView中的2个UITableViews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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