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
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.
精彩评论