views:

230

answers:

2

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

A: 

Hi, i wanna do the same thing in my app, if you figure out solution then do share here and I will do the same if I figured out first.

Ayaz Alavi
I think I'll implement the wrapper view.and use the show/hide views.
embedded
Ok. What about separate views for each screen and use [self presentModalViewControl:controllerforSegmentX ] for pushing views. controllerforSegmentX instance might be created using switch statement over segment index. Are u planning to created UITableView instances in the same viewcontroller and show/hide them upon touch event.
Ayaz Alavi
You should have 2 instances of viewcontroller each containstableview.this works for me!
embedded
A: 

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.

marcio