I have a TabBarController with two tabs SCHEDULE and DATE RANGE
When the view loads I'm hitting a webservice to collect the end users Schedule for that day. After parsing the XML I call ScheduleTable reloadData and all is well. I have tons of NSLog statements to follow the performance.
Clicking the DATE RANGE tab displays a DatePicker. After selecting the date range I have a button which when clicked passes the dates to the webservice again. In my log I can see the new dataset and can verify I have the data I need, when the code reaches the reloadData line, it does not fire the UITableView reload methods.
Any help is appreciated. I've tried viewWillAppear and self.ScheduleTable reloadData, neither have helped.
Check to see if you've connected the UITableView to the ScheduleTable IBOutlet in Interface Builder.
You say that the first refresh is working. That may be because it is automatically done by the tableview.
I understand that the second time you are calling reloadData programatically. If you haven't connected the IBOutlet, then your ScheduleTable variable is nil and [ScheduleTable reloadData] will do nothing.
when the code reaches the reloadData line, it does not fire the UITableView reload methods. Any help is appreciated. I've tried viewWillAppear and self.ScheduleTable reloadData
Just before saying [self.scheduleTable reloadData] (never start an ordinary variable name with a capital letter), log the table:
NSLog(#"%#", self.scheduleTable);
I'm betting it won't be the table and that you're accidentally sending this message into empty air.
Related
I'm having a difficult time understanding what I should even be looking for to debug this issue.
I have a UITableView that populates correctly.
I select one of the UITableViewCells which upon selection presents a new view to the user with more detail.
If I click Back on this new window, the original UITableView shows none of the UITableViewCells anymore.
I guess the problem is when you are coming back, your array is being empty somehow. In your first "ViewController" override the "viewWillAppear()" method and print the count of your array in this method. Then load the app and check the print result, then go to second "ViewController" and press the back button and see the print results again. if it shows zero "0" then check your code and try to find out where your array is being empty.
Hope this will help.
I ended up setting the delegate and datasource in the viewDidAppear() rather than the viewDidLoad(). Once I did that, I added a tableView.reloadData() inside of the completion handler for retrieving the data from the API and the tableView was then being populated as expected.
A simple tableviewController, empty. A modal that can be launched from a button. No data in the data source for the tableview, and no rows displayed.
I open the modal, use it to add an item, and return to the tableview controller. The tableview updates itself automatically, and the new row is displayed.
I add a second item. The table view does NOT update automatically.
I can tell by logging inside numberOfSectionsInTableView that even if I go to add the first item and cancel, the tableview refreshes - it asks for the number of sections, rows, and the cell to display (if there is one). But not if there is one pre-existing row in the table.
I've scoured my code but can't find anything that would cause the tableview to know when the first item is added, but none afterwards.
Any ideas?
EDIT - I have further narrowed my issue so will close this shortly and have posted a more specific question at Why does an empty tableView check the number of sections but a non-empty one does not?
from Apple's documentation:
UITableView overrides the layoutSubviews method of UIView so that it
calls reloadData only when you create a new instance of UITableView or
when you assign a new data source.
maybe you are setting data source of table view after showing that modal? So at the second time data source does not changes and tableView does not update.
another key (I'm not sure about that) may be the showing of the modal first time. The method -addSubview for modal is causing -layoutSubviews.
I've been stuck on this for all day.
I have a Nib file with a custom table cell wich I use to load into a
tableView instance variable of a view controller.
In the view controller I have a Search Bar and a Table View IBOutlets and a NSMutableArray to store my data as instance variables, among other stuff.
I have an object wich does asynchronous calls to an external API using Restkit so I define my view controller as it's delegate to receive the data when the request is finishe, save it on the NSMutableArray and then trigger a reloadData.
Because I'm making asynchronous calls the method shouldReloadTableForSearchString is in charge of sending the request and then return NO.
If I return YES instead of NO, making a call to reloadData after, my cells get loaded into the tableView one step back of my calls, that means that if I type the first letter nothing happens but on the second letter I get the results from the first letter. That behavior it's ok because the instance variable are setted after shouldReloadTableForSearchString returning YES. That is expected, Ok.
The problem that I'm facing is that if I use only reloadData, with shouldReloadTableForSearchString returning NO, the cells are not being assigned to the tableView. I checkhed and cellForRowAtIndexPath is being called and every cell is created with the data but it does not show.
Maybe I have problems with the datasource property, but I'm not sure.
I don't get the difference. Any Ideas?
The first time my UITableView loads, my cellForRowAtIndexPath method gets correctly called. The subsequent times I show my IUTableView, this method is not called and the old data is shown.
Neither are the viewWillAppear method nor the numberOfRowsInSelection called.
Anyone know what could be wrong?
Thanks
Deshawn
When you get your new data, fire -reloadData on the table view. It'll run all its data source methods to get a fresh look at its source data.
Don't tie that reload on the display of the view. Tie it to when you receive the new data.
Maybe I'm missing something obvious, but I'm have a hard time programmatically setting the row selection in a tableView. The goal is to simply have a tableView open with a row already selected. The problem appears to be that I have to wait until the tableView is fully loaded before I can modify the selection.
I've read various strategies such as calling reloadData for the tableView in the viewController's viewWillAppear method, then immediately calling selectRowAtIndexPath for the target row. But when I do that, I get a range exception because the tableView has zero rows at that point. The UITableViewDelegate methods (numberOfRowsInSection, etc.) don't appear to be called immediately in response to reloadData (which makes sense if the table rows are drawn "lazily").
The only way I've been able to get this to work is to call selectRowAtIndexPath after a short delay, but then you can see the tableView scroll the selected row into view.
Surely, there's a better way of doing this?
Well, you can use another strategy. You can create a hidden table view, configure how you want and than show to user. Use the tableview.hidden = YES.