1.Create one view controller say: MainViewController inherits UIViewController(not UITableViewController).
2.In MainViewController create two tableView say mTableView1 and mTableView2 and assign tag to both the tableview say 100 and 101 respectively.
3.Create one variable which will store the value based on segment selected say if first segment is selected then var = 100 and so.
4.In tableview datasource and delegate methods use this var to find out which segment is selected, and display respective tableview.
And if your tableview structure and functionality is same then you can even use single tableview and pass data to display in tableview depending upon segment selected.
Code:
In viewDidLoad add following code:
m_TableView1 = [[UITableView alloc] initWithFrame:yourFrame];
m_TableView1.tag = 100;
m_TableView1.dataSource = self;
m_TableView1.delegate = self;
[self.view addSubview: m_TableView1];
[m_TableView1 release];
m_TableView2 = [[UITableView alloc] initWithFrame:yourFrame];
m_TableView2.tag = 101;
m_TableView2.dataSource = self;
m_TableView2.delegate = self;
[self.view addSubview: m_TableView2];
[m_TableView2 release];
Then in datasource and delegate methods use tag and provide appropriate data as follows:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if(tableView.tag == 100)
cell.titleLabel.text = [NSString stringWithFormat:"First table, cell%d",indexPath.row];
else
cell.titleLabel.text = [NSString stringWithFormat:"Second table, cell%d",indexPath.row];
}