views:

535

answers:

2

I am having a SampleViewController in which a segmentedControl is added at the top below nav bar(not inside it).Now below the segmentedControl i want a tableView which loads from another class CommonTableViewController. When a segment is tapped the a new tableView from same CommonTableViewController should be loaded. How can it be done? thanks in advance.

+1  A: 

If you already have 2 UITableViews then just remove the first from the screen and add the other. LIke

[tableView1 removeFromSuperview];
[self.view indertSubview:tableView2 atIndex:self.view.subviews.count];

Depending on the case, you might also want to consider haveing one tableView and just changing the data.

Dimitris
No, I dont have 2 tableViews, a single tableViewController. I have added a UIView below SegmentedControl and adding the tableView as a subview on it. then when segment is tapped, the current tableView is REMOVEDFROMSUPERVIEW and new tableView is added as subview.Is the approach correct. Alos, the tableView doesnot scroll till end of footerview, it stops at the end of last row thats it. Whereas when I load the tableView separately in completely new view, the scrolling behaviour is correct. why it is happening with the same TableView. alos
its also not alos, sorry for the typo mistake
I'm not sure I understand really. So you `do` have 2 UITableViews and you `do` switch them and that works, right? So the issue is just the fact that the footer of both of the tableViews is never shown? For the footer, make sure you set it up correctly.
Dimitris
+1  A: 

I use an array to populate my tableView...

In my segmentedControlClicked method... I change the data in the array based on which segment was selected and then use this line of code:

[self.tableView reloadData];
Ben Call