One UITableView - Multiple DataSource, best design pattern?

送分小仙女□ 提交于 2019-12-03 00:39:26

Be careful with your terminology here. A UITableView has something called a dataSource but you seem to be referring, essentially, to two different sets of data.

In the case you're suggesting, in the table's dataSource (the object that adheres to the UITableViewDataSource protocol), I'd have three arrays.

  • currentlyViewedArray
  • datasetOneArray
  • datasetTwoArray

In the dataSource methods, use the currentlyViewedArray as the source of the table's data.

Then, set the currentlyViewedArray to whichever array you want to view:

self.currentlyViewedArray = self.datasetOneArray;
[theTableView reloadData];

You can use the UISegmentedControl to switch between the two arrays.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!