UISegmentedControl - how to toggle between 2 UITableViews

三世轮回 提交于 2019-12-25 04:56:04

问题


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

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