我如何用两个数据源创建一个UITableView [英] How might I create one UITableView with two data sources
问题描述
我有一个带有UITableView的UIViewController。但是该tableView有两个数据源。基本上,UIButton将决定哪个数据源处于活动状态。我该怎么办?没有这样的方法
I have a UIViewController with one UITableView. But that tableView has two data sources. Basically a UIButton would decide which data source is active. How might I do that? there is no such method as
[self.tableView reloadData:myDataSourceArray];
这将有助于很大程度地区分使用哪个数据源和使用哪个UITableViewCell扩展。那么我该怎么做呢?
Which would help a great deal towards discriminating which data source to use and which UITableViewCell extension to use. So how might I go about this?
我说的是按钮保持简单,但实际上,dataSource_1是从服务器预加载的,而dataSource_2是由UISearchBar加载的。
I say button to keep it simple, but in reality, dataSource_1 is preloaded from server while dataSource_2 is loaded by a UISearchBar.
推荐答案
您应该使用BOOL来跟踪哪个数据源处于活动状态。这是必需的,因为您还将使用UITableViewCell的两个不同的扩展类。说
You should use a BOOL to track which data source is active. This is necessary because you are also using two different extended classes of UITableViewCell. Say
BOOL dataSourceOneIsActive;
执行 cellForRowAtIndexPath
或 numberOfRowsInSection
您可以检查
if(dataSourceOneIsActive)
以确定要使用的计数以及使用的单元格和数据源。
to determine which count and which cell and data source to use.
另一方面,如果您使用NSMutableArray的想法,那么当需要决定使用哪种单元格类型时,就可以为您完成工作。
On the other hand, if you use the NSMutableArray idea, then you will have your work cut out for you when it comes time to decide which cell type to use.
这篇关于我如何用两个数据源创建一个UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!