UISegmentedControl-如何在2个UITableViews之间切换 [英] UISegmentedControl - how to toggle between 2 UITableViews
问题描述
我有一个基于标签栏的应用程序。
在2个不同的UITableView视图之间切换的最佳方法是什么?
I have a tab bar based application. What is the best way to toggle between 2 different UITableView views?
我应该使用包装器视图并将这2个视图添加到其中,并取决于哪个段选择了
,我将显示正确的视图吗?
Should I use a wrapper view and add those 2 views to it and depending on which segment was chosen I will show the correct view?
仅使用一个tableView无效,因为这两个
2个tableview的布局不同。
Using only one tableView will not work because the layout is different between those 2 tableviews.
谢谢
推荐答案
我通常采用不同的方法:我更喜欢为tableView的单个实例使用不同的dataSource,然后在它们之间切换(通常通过在segmentedControl上选择不同的索引)。
再次给您一个示例:
I usually take a different approach: I prefer to use different dataSources for a single instance of tableView and then switching between them (usually by selecting a different index on a segmentedControl). Again, just to give you a sample:
MyTableViewController: UITableViewController {
...
id<UITableViewDataSource> dataSource;
}
然后在实现文件中:
[...]
dataSourceIndex = indexValue;
NSString *currentClassName = [classNameModels objectAtIndex:indexValue];
Class currentClass = [[NSBundle mainBundle] classNamed:currentClassName];
dataSource = [[currentClass alloc] initWithController:self];
[self.tableView reloadData];
致谢。
这篇关于UISegmentedControl-如何在2个UITableViews之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!