UITableView weird reloadData issue - ios

I am stuck in a really weird issue, What em doing is calling NSURLConnection sendAsynchronousRequest in which i reload tableView and it does it without any issue. This scenario works fine while em standing on the same ViewController while request response is received. The issue arises when I call sendAsynchronousRequest and move from that ViewController and then come back to it before the request gives the response. This time the TableView reloadData gets called but doesn't do anything on the View. I call the reloadData in this dispatch_async(dispatch_get_main_queue(), ^{}); for it to run on mainThread.
Any help in this regard would be great.
Edit 1:
Here's what i have gotten far till now.. when i start the NSURLConnection asyncRequest it keeps the reference to the tableView and array that it has at that current time.. But when i navigate off from that view and then come back the view is reinitialized so the tableView and array has new references. So when the asyncRequest calls tableView ReloadData, it calls reload for the older referenced tableView rather than the one that is now visible hence not reloading the tableView… hope now you can help.

Rather than reloading tableview on main thread, try to reload it once you get data and the data is parsed. Switching between views may cause your tableview to reload before the data comes from server resulting blank tableview and this is caused due to calling some methods on main thread.
EDIT: Try to initialize tableview in viewdidload only and array just after you get response from server and before loading data in it.

Related

visibleCells are empty after reloadData/invalidateLayout - how to retrieve the visible cells at the correct time

I want to access the visibleCells in scrollViewDidEndDecelerating, but I get an empty array. The reason is that I called reloadData and invalidateLayout shortly before in viewWillLayoutSubviews and it seems that both functions (scrollViewDidEndDecelerating and viewWillLayoutSubviews) are asynchronous. Even if want to get the visible cells, right after calling reloadData I get an empty array. So it has not been finished recalculating everything.
How do I know at which time/which method there are valid visible cells? Do I have to force everything running on the main UI thread or how do I run that in sync?
Edit:
My solution is to use another approach and don't use the visible cells for this.

Why crashes UISearchBar after reload TableView

I have tableView with UISearchBarDisplayController. The below code was fetch record from webserver and display the tableview cell every works fine. but when will scroll 3 or 5 time downwards and upwards through i will going to click search bar it will crash the crash report NSLog doesn't print anything.
Remember i tried NSZombie , breaking point,exception point etc., but nothing helps.
Important question:
How to load data to tableview after fetched data from webserver. because tableview delegates methods are called before fetching data from server.
DataFetchController *getDataFetch=[[DataFetchController alloc]init];
//getleadFetch.delegate=self;
[getDataFetch beginTaskWithCallbackBlock:^(NSArray *mm){
[self.tableView reloadData];//if i comment this line the UISearchBar not crashes
}];
Loading the tableview before the data fetch is complete will obviously result in a crash.
So to avoid that we need to know when the data fetch is complete.
This can be easily obtained from your sql apis which return an error code when the fetch is complete. You can via that to find out if the fetching is complete or not.So sequentially you can provide the reloading of your table view command.
Hope it helps!!
update tableview data in main thread it not crash.
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});

Web services data is coming late and table view is empty

I am new to ios sdk, working on app which includes web service calling and parsing JSOn.i have two view controllers on first view i am calling web service on button click and in second view i have to display all record in table view. everything working well , parsing values are also coming properly. but values are coming late and table is displaying empty values. but when i am navigating back and coming again then it will display all button.How to handle this situation?
The beauty of Asynchronous download is making things ready for us in other than main thread. All UI components gets updated by Application main thread, In your case TableView UI updating on main thread and downloading happening in separately. I guess only thing you might missed here is, after downloading finished not getting the notification. Once you arrange notification after downloading process finished, just update your tableView by calling [tableviewobject reload];. Which ll done all reloading of the tableview(this is nothing but refreshing all tableview again). Good luck.
Are you reloading the table view once the data has been downloaded?
Something like this in your Table view controller:
[self.tableView reload];

UITableView reloadData fires only once

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.

UITableView not showing new cell data

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.

Resources