views:

284

answers:

1

Hi there,

I would like to use and display two tables on a UI view. Please let me know how to do this. Any code same will also be appreciated.

Thanks, Sandeep

+5  A: 
  1. Add 2 UITableViews to your view in IB and connect them to 2 different outlets in file owner (or simply assign different tag properties).
  2. Set delegate and data source for them (may be same view controller for both).
  3. In delegate/data source methods you do the following:

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    
        if (tableView == myFirstTable)
            // return value for 1st table
        if (tableView == mySecondTable)
            // return value for 2nd table
         return 0;
    }
    

or if you use tag approach:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{   
    switch(tableView.tag){
         case firstTag:
            // return value for 1st table
         case secondTag: 
            // return value for 2nd table
    }
    return 0;
} 
Vladimir