Loading .xib in the simulator versus a device

Discussion in 'iOS Programming' started by MvR, Oct 4, 2008.

  1. MvR macrumors newbie

    Joined:
    Jul 29, 2008
    #1
    I have a .xib file containing a single custom UITableViewCell at the top level, as well as the File's Owner (NSObject) and First Responder.

    From the many examples posted online, I then do

    Code:
    NSArray *topObjs = nil;
    topObjs = [[NSBundle mainBundle] loadNibNamed:@"MyTableCell" owner:self options:nil];
    MyTableCell *cell = (MyTableCell *)[topObjs [B]objectAtIndex:1[/B]];
    
    This all works fine in the simulator. The array topObjs contains two objects.

    When running on the device however, the array only contains a single object, forcing the following change:

    Code:
    MyTableCell *cell = (MyTableCell *)[[B]topObjs objectAtIndex:0[/B]];
    
    Could anyone please explain this difference? Thanks.
     
  2. SqueegyX macrumors regular

    Joined:
    Mar 24, 2008
    #2
    Whats the object in the forst spot in the simulator?

    And you should probably set the class of the File's Owner to the class that wil be using that xib file (MyTableCell).
     
  3. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #3
    I'm not sure of what the objects are in the array but I don't think that's how you should do this. Instead, have an outlet for the tableviewcell in your view controller. Set the File's Owner type correctly and connect the cell to the outlet in the File's Owner. Once you load the nib the outlet will hold the pointer to your tableview cell.

    Many examples posted online? I didn't think anyone was doing it this way.
     

Share This Page