Two TableView in One ViewController

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == table1)
    {
        return 5;
    }
    else if (tableView == table2)
    {
        return 5;
    }
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == table1)
    {
        return 30;
    }
    else if (tableView == table2)
    {
        return 40;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == table1)
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"table1"];
        
        cell.textLabel.text = [NSString stringWithFormat:@"first tableView:%ld",(long)indexPath.row];
        
        return cell;
    }
    else if (tableView == table2)
    {
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"table2"];
        cell.textLabel.text = [NSString stringWithFormat:@"second tableView:%ld",(long)indexPath.row];
        return cell;
        
    }
    return 0;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == table1)
    {
        NSLog(@"First TableView Index: %@",[NSString stringWithFormat:@"%ld",(long)indexPath.row]);
    }
    else if (tableView == table2)
    {
        NSLog(@"Second TableView Index: %@",[NSString stringWithFormat:@"%ld",(long)indexPath.row]);
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s