tags:

views:

651

answers:

5

I have a UITableView on one view that loads in data at the start of the application, and then later when a user enters text into a box and hits a button, I re-query the database, re-populate the original NSMutableArray that stores the data for the table.

All of that is working perfectly. In some logging statements I can tell that the array has the correct information, the numberOfRowsInSection method is returning the proper count, and is being called after the reload is called.

However, the cellForRowAtIndexPath is never called the second time (after the reload) and the table data is never updated.

I've spent hours searching the net and I've found nothing that helps. Can anyone help?

All code is at: http://github.com/botskonet/inmyspot

The specific reload is being called at: http://github.com/botskonet/inmyspot/blob/master/Classes/InMySpotViewController.m

Roughly Line 94

From: http://github.com/botskonet/inmyspot/blob/master/Classes/PlateFormViewController.m

Roughly line 101

A bit more info: once the new data has been added to the mutablearray, if I try to start scrolling the table, it eventually dies with:

"Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSCFArray objectAtIndex:]: index (29) beyond bounds (29)'"

Which I assume means the table cells can't find any data in the array to match the scroll position, which seems to be because the array has the new data, but the table doesn't.

A: 

Your reload is not being called because you haven't setup your delegates for UITableView properly.

@interface InMySpotViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource>{
}

Also you overwrite mainDelegate.plates here:

NSMutableArray *platesArray = [[NSMutableArray alloc] init];
                mainDelegate.plates = platesArray;
                [platesArray release];

Why not combine your two controllers. The way your doing it is leading to most of your problems. You create a new InMySpotViewController unnecessarily in PlateFormViewController.

Jordan
I've updated the delegates for the controller, so far it had no effect. However, the code that updates the plates array is actually supposed to - it's loading in a new set of database results. Thanks!
BotskoNet
I've combined the two controllers, and I'm again getting the table covering up all of the other text/button elements. http://github.com/botskonet/inmyspot/tree/views
BotskoNet
Are you setting the frame size of the UIViewControllers appropriately?
Jordan
You haven't added the UITextField, UILabel, or UIButton to the viewController (InMySpotViewController), using addSubViews, that's why they don't show up.
Jordan
A: 

In plateLookup you clobber the existing array:

    NSMutableArray *platesArray = [[NSMutableArray alloc] init];
    mainDelegate.plates = platesArray;
    [platesArray release];

After this you reload the table. The array has zero elements so cellForRowAtIndexPath: is never called.

Edit: You also create a new view controller

        InMySpotViewController *viewController = [[InMySpotViewController alloc] init]; 
        [viewController refreshTable];

So you're not even reloading the table that's visible on the screen.

Darren
The plates array "clobber" is supposed to be loading in a new set of database results, so I believe this is how I want it to work. The plates array is properly receiving the new data set. However, I suppose I am creating a new view which makes sense why the tableView I have on screen isn't updating. How can I fix that?These views are separate because I had previous problem where the table was covering up my other elements no matter how I tried to do it, and no one had any ideas why.
BotskoNet
Set a breakpoint at the end of plateLookup, then inspect the contents of platesArray. You'll see that the array isn't reloading like you think it is. That's why you're getting the Index out of Bounds exception.
Darren
A: 

Thanks to some debugging by a family member I've determined the following issues were the cause:

  • The inMySpotViewController was setup as a UITableViewController not a UIViewController which is why the table was covering up everything else. I changed it to a UIViewController and then added a new UITableView:

    IBOutlet UITableView *myTblView;

    @property (nonatomic, retain) UITableView *myTblView;

And then referenced that table view throughout my code. This code was done on the single-view branch so it's now working properly.

The platesArray kept being mentioned as a problem, but it's not because the out of bounds was happening because the array was successfully being updated, whereas the table view was not (so I was trying to scroll to an index in the array that didn't exist, but I knew that was the problem since they table didn't visually update).

I had successfully logged out the contents of the revised plates array after re-writing it's values and they were all correct, and plates.count was returning the proper values, so it was not getting "clobbered" in anyway.

Thanks everyone for the help!

BotskoNet
A: 

I was seeing the same issue. My problem was similar: I have a UIViewController subclass (MyViewController) that contains a few things, including a reference to my subclass of UITableViewController (MyTableViewController). In MyViewController.xib, in order to make sure that the tableView that is loaded by the MyViewController is the same one as the one loaded in MyTableViewController, in Interface Builder I hooked up the reference from the tableView in MyViewController and made it point to MyTableViewController's view property.

Here's a picture, since actions in Interface Builder are so hard to describe: http://dl.dropbox.com/u/155886/screenshots/Screen%20shot%202010-04-19%20at%207.11.02%20PM.png

commanda
A: 

thanks commanda - your screen clipping saved me a ton of time on a complex situation...

biozal