cellForRowAtIndexPath returns nil on device - iphone

I spent few hours trying to resolve one very strange issue, but I really don't know how to proceed.
I have a grouped UITableView referenced from XIB populated with custom (subclassed) UITableViewCell cells. All the cells (two section with one cell each) are visible and I am trying to get one of them by calling:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:1];
LocationSearchFilterCell *cell = (LocationSearchFilterCell *)[filterTable cellForRowAtIndexPath:indexPath];
On Simulator 4.2 the cell is returned properly;
On Device 4.0.x the code returns NIL;
On Simulator 4.0.x the code returns NIL;
On Simulator 4.1 the cell is returned properly BUT NOT on Device 4.1.
The strangest thing is that I am using this approach on few other places within the application and the cell is always returned properly. I guess it is some strange combination of me doing something differently combined with some iOS bug.
Any idea ?
P.S. In situation where NIL is returned, by using GDB I get the pointer of the cell when it is created and call:
(gdb) po (void *)[filterTable indexPathForCell:(UITableViewCell *)0x7b08520]
and I get a valid index path (that matches the one I am providing) which means the cell is valid and present into the table view.
I have even tried passing the object returned by this last call (by pointer) and I still get NIL.

Interesting,
It turned out someone is hiding the table view before I try to get the cell (stupid me :)).
What I was doing was, triggering an animation to hide the table view (nested into some methods I am calling from the method where I try to get the cell). Because I was stopped on a breakpoint the animation was also stopped, so it seamed to me like the table view is visible.
What I don't understand still is why the table view is threaded as hidden although the animation is still not finished (and I only change the frame in the animation and set the table hidden after the animation is finished) ?
I guess the answer to this question is the key point why on different combinations of Device / Simulator / iOS I get different behavior. Anyway the solution is as simple as moving the two lines I've posted above at the top of the method.
Thanks to Rits for his question that triggered my reasoning ;)
regards

Related

`[[self tableView] reloadData]` changes the NSMutableArray count

I have an app that uses a UITablewView and in that TableView there is an NSMutableArray that holds the data to be displayed in the TabelView.
The problem is in my TableView Controller I use:
[[self tableView] reloadData]
To reload the TableView data and it works fine for a couple of times but doesn't work on the 3rd time and instead it changes the array count in a weird way.
Now I read similar question here and most likely I have 2 instances of the TableView or the TableViewController but I can't figure out how to troubleshoot this? How to detect if there are 2 instances of the object and fix that?
EDIT: Here is a pic how my navigation goes
So the 1st round of going from ScrollView to TableView things show up correctly. Then I go to UIView and back to TableView and it's working fine. So I go back all the way to ScrollView and back again to TableView and it's good.
But when I go to the UIView for this time then back to TableView this problem happens. TableView doesn't display the changes. So I put a breakpoint just before [[self tableView] reloadData] and found out that the array _displayedObjetcs gets its count changed. -1 actually. see the following screen shots b4 and after I step over the reloadData
and then
My immediate thought is that your array is not being retained properly, by your application. Your "weird" count is probably a number like 234791..., which is highly indicative of an array that has been released incorrectly. Therefore, I would check how your are retaining and releasing this array.
However, without more posted code, it is impossible to help you further.

Updating gps locations in a uitable view in the cell.detailTextLabel.text problem

I am working on a Core Location based application which displays the name of the place you are heading towards in the UITableView text and display how far away from the location you are from in the cell.detailTextLabel.text.
I have GPS delegate that updates the location and I set a Core location getter and setter and try to use that location to set the cell.detailTextLabel.text each time I get an update.
But my problem lies in scrolling the UITableView. When i click on a cell is goes to where I want it to but if I try to scroll the view to see all the cells the app crashes and issues a bad access error. I don't know where there is a bad access in the location update or if there is a better way to get the gps locations into the cell.detailTextLabel.text and update it better than get the new location and reloading the data.
any help would be greatly appreciated.
thanks
Almost certainly you have an error in your UITableViewDataSource or UITableViewDelegate methods. If you don't get the count of sections and cells right or if you don't return a valid cell as required you will always crash. Some NSLogs in these functions might help you to spot any problems as they occur.
Next make sure to set the environment variable (doubleclick the app executable, select arguments) and add "NSZombieEnabled" with value YES. If you are releasing something that your table later uses, EXC_BAD_ACCESS is the result and this will cause a debugger breakpoint rather than just a mysterious crash - with a stack trace you should be able to easily find the problem.
You're using reloadData to refresh the table view cell?

TableView's viewWillAppear() called but data is not refreshed

Sometimes tiny looking problem is ignored to handle in the last but you never know that will become nightmare for you, happening with me.
Thanks in advance, problem my app's settings page contains tableView and every setting element is one of the view. One of the setting item (row) offers show expands a few list of items in another listTableView. After making a selection in listTableView when i come back to my settings tableView using navigationItem.leftButton (Back), selected item value overlaps the previous item's value, in the sense [tableView reloadData] in viewWillAppear works fine but tableView rows are not fresh drawn. It doesn't refresh the cell's UI.
Note that if settingTableView has any subview like UIButton etc it has the latest value, i can use that as workaround but the only problem is when is select this row again Selection has old value that overlaps new value on selecting the row.
I will appreciate any suggestion or sample code using will be great help.
Thanks a ton
Amit Singh
Use [tableView reloadData]; in your viewWillAppear method.
or use [tableView reloadData]; in viewDidAppear method
The problem you are facing is perhaps due to portion of cell that is reusable and the one that is not reused. Check out the code you are writing inside the block of
if(cell==nil){}
components you have created inside block will not get recreated and others might be recreating causing the overlapping on the cell.
In my case, I had to use [self.tableView reloadData]; rather than [tableView reloadData]; in the viewWillAppear method.

UITableView not populating in Tab bar iPhone application

I have a tab bar application which loads a UITableView when one of it's buttons are selected. It seems to load the view controller however it doesn't seem to be populating the data. I have tried setting the cell.text = #"cell" (while setting the number of rows > 0) and an NSLog in the CellForRowAtIndexPath proves that in fact the function is not being called. The same NSLog output to the console in the viewDidLoad function also generates no output so it seems as though its not getting called.
Any suggestions?
Try and call [tableView reloadData] from your -(void)viewWillAppear:(BOOL)animated; method. This should be called each time the user navigates to that tab and should set off the delegate callbacks that aren't currently being called. If they still aren't called make sure you have set the table delegate to self.
EDIT: Actually make sure you have set your table view's delegate and datasource to self;

Problem reloading UITableView

I have a UITableView which is populated by an array, I have a button on the navigaton bar which (when pressed) adds an item to the array and calls [self.tableView reloadData] in the UITableView. This results in numberOfRowsInSection being called and returning the correct number of rows (the number of items in the array) BUT doesn't call cellForRowAtIndexPath.
I have created a new navigation based application to try and find a solution but have exactly the same problem!
If anyone knows the answer it would be greatly appreciated, i've been tearing what's left of my hair out for the last day!
I have put the source for the test project up on my site at www.sofaracing.com/Downloads/Test3.zip
Works for me! ;)
In MainWindow.xib, You added an object Root View Controller (that's not part of the Navigation Controller) - Delete it, not necessary. Then connect outlet refreshFriendsList to the Bar Button of the NavigationItem of RootViewController. Wha-la, magic!
BTW: You may need to clean up the warning. And you might want to think about creating a class for your data model instead of using UIApplication sharedApplication.
I quickly debugged your test app. I couldnt't spot the root cause, but it seems that you have two different table views due some mess up in Interface Builder setup.
If you initialize original array with an item, cellForRowAtIndexPath is correctly called. If you examine self.tableView instance in this call and later in subsequent calls to refreshFriendsList, self.tableView points to a different instance.
2009-05-17 14:33:07.591 Test3[33580:20b] cellForRowAtIndexPath 0
2009-05-17 14:33:07.594 Test3[33580:20b] self.tableView: <UITableView: 0x52b9b0>
2009-05-17 14:42:36.810 Test3[33762:20b] numberOfRowsInSection: tableView <UITableView: 0x53bcd0>