Two TableViews in a single ViewController ??

Discussion in 'iOS Programming' started by Fritzables, Jul 7, 2012.

  1. Fritzables macrumors regular

    Joined:
    May 6, 2011
    Location:
    Brisbane AUSTRALIA
    #1
    Hi All,

    I am writing an application suitable to Maintenance Planning.

    The application is for the iPad (Only) and using the latest XCode 4.3.3 and StoryBoards.

    In the past my applications have only had a single UITableView for each ViewController, so setting delegates and datasources or even control Row Height and other parameters reasonably straight forward.

    Now, there is a need to have a ViewController that contains two TableViews as shown in the attached file.

    As you can see I have placed the GUI TableViews onto the ViewController and have not placed them there programatically.

    To gain access to the Tables parameters and properties I have declared the UITableView in the Header for the ViewController:

    Code:
    @interface VehicleViewController : UIViewController {
     
        UITableView *listVehicle;
        UITableView *listMaintenance;
    }
    
    @property (nonatomic, retain) IBOutlet UITableView *listVehicle;
    @property (nonatomic, retain) IBOutlet UITableView * listMaintenance;
    ...
    After Synchronising I can then set a number of parameters like rowHeight, numberOfRowsInSection:

    But I am not sure how to access each tables cell’s properties. With a single table one would use:

    Code:
    (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    	static NSString *CellIdentifier = @”Cell”;
    }
    and all the other various methods associated with the cell.

    So, how is this best done??

    Pete
     

    Attached Files:

  2. CodeBreaker macrumors 6502

    Joined:
    Nov 5, 2010
    Location:
    Sea of Tranquility
    #2
    This is trivial, as you have references to both your tables. In the delegate methods of your tables, you just have to check which table called it, and return appropriate data.

    Something like this:

    Code:
    (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if ([tableView isEqual:self.listVehicle]) {
            static NSString *ListVehicleCellIdentifier = @"ListVehicleCellIdentifier";
            //do the usual cell deque/alloc/configure stuff here, and return the cell
            
        } else if ([tableView isEqual:self.listMaintenance]) {
            static NSString *ListMaintenanceCellIdentifier = @"ListMaintenanceCellIdentifier";
            //do the usual cell deque/alloc/configure stuff here, and return the cell
        } else {
            NSLog(@"I have no idea what's going on...");
            return nil;
        }
    }
    
     
  3. Fritzables thread starter macrumors regular

    Joined:
    May 6, 2011
    Location:
    Brisbane AUSTRALIA
    #3
    Thanks CodeBreaker..... looks like the trick.

    Thanks again.

    Pete
     

Share This Page