views:

73

answers:

2

I have a UITableView with two sections, which are both empty when my application launches. My app fetches the data from a URL, then puts the data into arrays (one per section) which should be used to supply the UITableView data for each cell.

Calling [tableView reloadData] doesn't seem to refresh any of the data, or call any of the delegate methods. (such as requesting the number of sections and rows, etc. although I don't know if it's actually supposed to)
I'm using custom UITableViewCells, if that helps.

I've also tried refreshing the sections, and looping through the data to add every individual cell into the sections. Nothing seems to work.
I've checked again and again, everything seems to be right, and the UITableView is connected properly in Interface Builder.
I have two other table views in my application (in other tabs, it's a tab bar app) which work perfectly fine, although they are both have only one section.

A: 

If you put a breakpoint on that line, and mouse over "tableView", does it say the memory address is 0x0?

Steve
Yes, it does. I'm guessing that's a bad thing... any idea why that happens?
ev0lution
Yes... that means the "tableView" you're referencing isn't the tableView you tried hooking up to IB. Try this; change the name of your outlet from tableView to myTableView (or something else), but don't name it anything similar to something that might just happen to already exist on your view controller. Hook everything back up to your newly named outlet (and make sure you change any underlying ivar name as well)... and I'll bet you it will start working.
Steve
Unfortunately it didn't work, it still returns null. I checked in one of the table view delegate methods, numberOfSectionsInTableView, and the correct table view is being called in it. Then somehow when I refer to that table view later, it's null.
ev0lution
I'm assuming the code is private, and you can't post the project anywhere?
Steve
Well I'd rather not... I'm guessing now that the reason it won't work is because I'm trying to call it from another view controller, although that doesn't really make sense because I can access everything else using the same method.
ev0lution
At least you know what the problem is now; that you're sending the "reloadData" message to nothing. If you can fix your reference, you'll be good to go.
Steve
How would I fix that? I can access other things in the view controller containing the table view, but not the table view. (and also, it's actually calling a function in the view controller to reload the table data, but that's not making any difference)
ev0lution
Sorta hard to tell without more information... you mentioned you have other IBOutlets hooked up properly, so clearly you know how to do that... if it were me i'd probably put a breakpoint in the viewDidLoad/Appear method and check to make sure the outlet is wired up properly. Out of curiosity, you mentioned it's on another view controller... can you give more detail about that? Maybe that's related to the problem.
Steve
The outlet is definitely connected properly. What I'm actually trying to do is get data from a URL connection in one view controller (displayed modally), then set that data and reload the table view in the view controller under it. (just before being dismissed)I think this is what the problem is, it seems it's not possible to update the table view via this method (though setting the data works fine), so I'm stuck as to how I can achieve this.
ev0lution
That's definitely possible. You say the outlet is hooked up properly... if that's the case, why is your outlet a null value?
Steve
That's exactly what I'm wondering. It's only when called from my other view controller that it is null, though. As (I think) I commented before, the delegate methods are called when the application loads, (when there is no data) and the IBOutlet works properly.
ev0lution
One of the parameters to those delegate methods is usually a reference to the tableView... are you sure the _outlet_ is hooked up properly... are you referencing the outlet from you delegate methods, or are you using the parameter in your delegate methods?
Steve
When I have to use the table view within a UITableView delegate method, I use the reference passed to the method. (I only ever need to use it in `cellForRowAtIndexPath` though) When the application loads, though, (the only time these methods are called) the outlet is set properly. I verified that by checking which table view is being called in the delegate methods.
ev0lution
A: 

Check a few things:

  1. Make sure tableView is connected up to File's Owner in IB
  2. Make sure tableView.delegate = self
  3. Make sure your datasource actually has data
Sheehan Alam
1. Already was2. Already was3. It does, but the methods are not being called for the cells to be created
ev0lution