how to pass multiple uitableviews to the tableView callback method?

Discussion in 'iOS Programming' started by johnmerlino, Jun 6, 2012.

  1. johnmerlino, Jun 6, 2012
    Last edited by a moderator: Jun 6, 2012

    johnmerlino macrumors member

    Joined:
    Oct 22, 2011
    #1
    Hey all,

    I have a uiview controller, with 4 uiviews and 3 of the 4 uiviews have table views. They are all connected to remoteTableViews:

    Code:
    @property (strong, nonatomic) IBOutletCollection(UITableView) NSArray *remoteTableViews;
    
    So all of the table views properly display for their respective uiviews. The problem is some of the table views cells are not populated with data. I believe it has to do with the fact that when the tableView callback is invoked on my uiviewcontroller, it seems to pass only 1 of the 3 table views:

    Code:
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    {
        static NSString *CellIdentifier = @"CellIdentifier";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
        
        if (self.fenceIsActive)
        {
            cell.imageView.image = [UIImage imageNamed:@"checked.gif"];        
        }
        else {
            cell.imageView.image = [UIImage imageNamed:@"unchecked.jpg"];
        }
        UILabel *cellLabel = (UILabel *)[cell viewWithTag:1];
        [cellLabel setText:[self displayLabelFor:indexPath.row]];
    	return cell;
    }
    Is there a way to pass all 3 table views to a callback so that all 3 table views get populated with the same data?
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    Give them all the same data source object.

    Or give each one its own data source object, but that object connects to a single underlying model object.
     
  3. johnmerlino thread starter macrumors member

    Joined:
    Oct 22, 2011
    #3
    My data source is stored in NSArray. I select table view and in connections inspector, i drag dataSource of the table view onto the nsarray instance var in .h but it doesnt connect.
     
  4. CodeBreaker macrumors 6502

    Joined:
    Nov 5, 2010
    Location:
    Sea of Tranquility
    #4
    You don't have to connect it with the ivar. Your view controller has to implement the UITableViewDataSource and UITableViewDelegate (if required) protocol.



    Then you can drag from the table view to File's Owner in Interface Builder, selecting dataSource.

    Alternatively, in your view controller's viewDidLoad you can do this:

    Code:
    [self.firstTableView setDataSource:self];
    [self.secondTableView setDataSource:self];
    
     

Share This Page