问题
I have a tab bar based application. What is the best way to toggle between 2 different UITableView views?
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?
Using only one tableView will not work because the layout is different between those 2 tableviews.
Thanks
回答1:
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;
}
then in the implementation file:
[...]
dataSourceIndex = indexValue;
NSString *currentClassName = [classNameModels objectAtIndex:indexValue];
Class currentClass = [[NSBundle mainBundle] classNamed:currentClassName];
dataSource = [[currentClass alloc] initWithController:self];
[self.tableView reloadData];
Regards.
来源:https://stackoverflow.com/questions/2833238/uisegmentedcontrol-how-to-toggle-between-2-uitableviews