Web services data is coming late and table view is empty - ios

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];

Related

UITableView data source change does not trigger UI update on iOS 13

This only happens on iOS 13.. iOS 12.x works fine.
I have a table view with a search controller, and two datasources, one for the regular functionality and one for the search functionality. (the search functionality is unrelated to the content displayed on the main table content).
After cancelling a search, the searchBarCancelButtonClicked: method is triggered, I switch from the search data source to the main datasource and reload the table view but even though the table view details show that the correct datasource is set, the UI still shows the search data source.
I tried triggering the layout refresh, but no luck.
Worth mentioning that the UITableViewDataSource methods are called on the correct data source, it's just the UI that's out of sync so to speak.
Any idea what could cause such a thing?
If I manually set the search controller inactive, it works: [self.searchController setActive:NO];

Show activity indicator while changing views (Segue) and load data for next view (API)

Umm I really need some help
I have a search view, when user clicks the cell (basically a game), the view changes to a Game View. Atm I was not using any async stuff so while the game view loads, the app kinda hangs for 2-3 secs on the search view after clicking the cell (since the viewDidLoad method of game view loads all data from web API)
What I wanted to do was when a user clicks game in searchView, the gameView instantly shows up with just a blank view and a Activity Indicator meanwhile the data is fetched from API.
Once data is fetched, the gameView (which is a tableView btw) reloads the data and shows it accordingly from the fetched data.
If it makes any diff. I am using static cells for gameView and thus not using cellAtRowIndex code.
I have attached images for some of my methods I tried to use as per my searching on SO for AFNetworking, async etc etc.
The table IB elements are filled from data in a separate function showGame, I am calling this function in rowsForSection since table will be reloaded after block completion. Excuse me but I wasnt sure what would be the best way to reload table or rather show the data.
Atm my app is showing me my default static content which I created in interface builder (and with only 1 row). AKA the table is not being updated. I used breakpoints to check and yeah the showGame is getting correct data, passing correct data to IB elements. Even the execution is reaching the point in code to return 5/6 rows BUT the actual app/view is not updating properly.
For those who want pastebin text code, here it is:
.m file where async code to fetch game from API is
http://pastebin.com/p2FETbku
.m file of my gameView class/tableView which shows the table view and data, this file also has the showGame method to show the game data fetched from above class
http://pastebin.com/cWtSKPw0
Please excuse my code or any small mistakes, I am still in learning phase and just started 3 weeks ago.
The static cells were working fine before I was using async method, somehow its getting messed up during/after that reloaddata
One point that I think you are missing is that execution of this statement
GDgameViewController *gdv = [[GDgameViewController alloc] init];
doesn't return the tableViewController hence the tableView that is currently presented.
So in your function +(void) fetchGame:(NSString *)gid what you are reloading is the tableView that is not presented.
To help you further I have created a project for you which use a bit different approach to do your work but it does it optimally. You can find project here. If you don't know how to use gitHub, don't worry just download the zip file. Please make this count as

Performance issue when reloading tableview section

When new data is received by my app, a notification is sent out and received by my view controller. The view controller then reloads one of the sections of its tableview. This typically takes just 40ms or so.
However, if I have pushed another view, the notifications are still processed by the original controller but the reload of the tableview takes about 10-20x longer.
I can certainly work on improving my tableview performance, but first I need to understand what is causing this. Would also appreciate some help using Instruments on how to debug this myself. So far I have run the 'Time Profiler' instrument and it looks like most of the effort is expended in system method, '[UIView(Hierarchy) layoutIfNeeded]'. This doesn't mean much to me.
You definitely don't need to be updating UI on an element that isn't onscreen. UI updates will take place in the main thread, which will negatively impact user experience.
Updating your data source (in a background thread) should be more then adequate, and then you can update the tableview when it is next shown to the user.

slow pushing when a tableview element is selected

In my app,i am using tableviews, populated through XML parsing, i get my XML from an ftp, the XML contains other xml urls for the next views and images urls and text, the problem is when an element of the tableview is selected it pushes to another view, But load for a very long time.
I run my app into the simulator, i never tested it on a device.
does anybody knows what may be the problem?
Is it a connection issue?
will it work fine on a device?
I would suggest testing your code on a device and not making assumptions about the peformace. I assume you are going to the server and ask for those images to display in the pushed view. In which case you should load the view with image placeholders and spin off the downloading images in a secondary thread (good habit for slow loading as to not block the UI) and update the image placeholders as the image data become available.
I will gladly update this answer if you need more specific help.
If you are loading a tableview in your pushed view, the hang will happen on the view before that pushed view (that is very terrible UX). So move the logic of the code that take a while into the subclass of the "pushed view", you can implement something like a spinner (I use MBProgressHud) while you crunch you data. This way you will get the view loaded before the lag begins.
Now the flow to improve UX can be as follows:
1. In the - (void)viewDidLoadof the pushed view you can hide the tableview (or not).
[self.myTable setHidden:YES];
2. In the -(void)viewDidAppear:(BOOL)animated of the pushed view throw up a spinner for the user to know you are doing work (work here being going to the server to look for the images from the urls) and do the work.
//your code here will vary
3. When you know that all your data is downloaded just load the table, hide the spinner and show the table. You can do this at the end of the -(void)viewDidAppear:(BOOL)animated method.
[MBProgressHUD hideHUDForView:self.view animated:YES];
[myTable reloadData];
I recommend sending all the expensive work into a secondary thread, because a user would hate to decide not to wait and have a blocked back button in the navigation bar. But for to answer you original question you pushed view should load immediately, but then wait to get the data.

UITableViewController on UISplitView. Why does drill down stay on 1st table? (using monotouch)

I'm using the UISplitView in my app with the left side (popover in portrait) utilizing a UITableViewController. I want to reuse the master table controller so when I want to drill down I create a new instance of the object and push that. However, when I set the data source, all the data goes into the 1st instance table (hope that makes sense). So if I hit the back button, the new data I thought was supposed to be on the pushed table is in the 1st table. Any ideas?
I sort of figured it out. I have an asynchronous operation occuring and it seems to have something to do with threading. When i call the method synchronously, everything works as expected.
When updating things in a callback you should use InvokeOnMainThread();
Otherwise you'll end up in a bad state :)
w://

Resources