Ugh, the UITableView is not refreshing. Ever.

Discussion in 'iOS Programming' started by MobiusStrip, Oct 13, 2010.

  1. MobiusStrip macrumors regular

    Joined:
    Dec 11, 2009
    #1
    Hi all.

    I have a pretty simple scenario: a view with one control on it, a UITableView. It's in a XIB owned by a controller for this view, derived from UIViewController. The controller has an IBOutlet for the UITableView, and it implements the necessary delegate protocol methods:

    Code:
    - (UITableViewCell*) tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath;
    - (NSInteger) tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section;
    These methods DO get called, and the cellForRowAtIndexPath is pretty much the boilerplate example that everyone uses, with mods for the way I'm storing data.

    Here's the hookup in IB:

    [​IMG]

    I don't have any separate threads, and I do call reloadData on the TableView. Nothing ever shows up in it; it stays empty. Any ideas?

    Thanks!
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Almost certainly the problem is in the code that you have not posted.
     
  3. MobiusStrip thread starter macrumors regular

    Joined:
    Dec 11, 2009
    #3
    Well, here are the delegate functions:

    Code:
    - (UITableViewCell*) tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
    {
        UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
    
        if (cell == nil)
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
    
        if(indexPath.row < stashes.size())
        {
            Stash* pCurrStash = stashes.at(indexPath.row);
            if(pCurrStash)
            {
                cell.textLabel.text = [NSString stringWithUTF8String:pCurrStash->getName().c_str()];
            }
        }
    
        return cell;
    }
    
    
    - (NSInteger) tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
    {
        return stashes.size();
    }
    Occasionally, an application event will occur and I call reloadData on the TableView, to pull in changed data from the collection. That's pretty much it for the code.
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    So have you put log statements in to check the sanity of various conditions? You know, ultra-basic debugging that any programmer would do? As an example the first thing I would log would be stashes.size().
     
  5. MobiusStrip thread starter macrumors regular

    Joined:
    Dec 11, 2009
    #5
    Yes, I've stepped through it. The collection contains entries, and the cell text is set to a legitimate string provided by that getName() call.
     
  6. MobiusStrip thread starter macrumors regular

    Joined:
    Dec 11, 2009
    #6
    Solved

    SOLVED. Turns out to be a simulator bug, or a bug in the way Xcode is loading apps into the simulator.

    The simulator was showing a UI from a XIB that had long since been deleted from disk and removed from the project. And yet the compiled nib from it was turning up in the app package, even after cleans.

    Even deleting that nib from the app bundle or deleting the whole build directory wasn't enough; it still showed up in the simulator. I had to manually invoke the app deletion on the simulator screen to get rid of it.

    Hopefully this info will save someone else some time. Needless to say, I filed it with Apple.
     

Share This Page