Populate UITableView with results of webservice - uitableview

I have a table view which i want to populate with the results (XML) of my call to a web service.
The NSURLConnection and NSMutableURLRequest that are doing the setup for this are currently in my -viewDidLoad method, and i also have all of my UITableView delegate methods in my .m file too.
The data is being returned and added to my array correctly. My problem is (i think) that the UITableView methods are being called before any data has been returned from the web service, which is why my table view is always blank.
How can i call the methods in the right order (if this is even the problem)...

Are you calling reloadData on the tableview once you've repopulated the array? You need to let it know that you have new data.

UITABLEVIEW *mytableview=[[UITABLEVIEW alloc]init];
[mytableview reloadData];
Yes you are right; the UITABLEVIEW delegates are called before the web service. So you have to call those delegates again so try reloading the data. Works perfect for me. reload table when u have something returned from the webservice. store it in NSArray or whatever and then reload table.

Check out Apple's SeismicXML code example on the developer.apple.com/iphone site. It shows how to use NSURL, NSXMLParser, and a TableView to do just this type of thing.

Related

Loading Data Asynchronously into UITableView

I am using xCode 7 beta and swift, and storing my data using Parse.com. In which method in the UITableViewController should I be asking for data from my database? I need to ensure it is all present by the point in the lifecycle of the controller at which the cells need to be presented.
Is there anyway to guarantee this if I am loading data asynchronously?
viewDidLoad would be a good place for this but there might be a few second difference between displaying a blank tableView and when it gets populated depending on how long it takes to pull your data.
So in viewDidLoad you'll tell the Parse SDK to pull data and when it's complete, you can call [self.tableView reloadData]
You should be asking for your data before the tableview is shown. That way you can pass your cells the ParseObject within the cellForIndexPath function. Then within your cell you can go ahead and get other information from ParseObject such as fetching relations or PFFIles etc

json webservice and uitableview

I have JSON web-service and my task is to parse the web service and store the data into UITableview.
I am parsing the web service using NSURLConnection methods.
After parsing the web-service i got the response what I wanted .
But the issue is that my UIViewController is calling UITableView Delegate and Datasource methods first and then it calls web-service so my UITableView doesn't get any response.
Even though I call the web-service first it calls all the UITableView Delegate and Datasource methods first and then web-service so my table view doesn't get any response.
After calling the web-service i get perfect response.
So if somebody knows any solution please help me.
Thank you.
The other answers in this thread should solve your problem.
However, if you find that [self.tableView reloadData] isn't refreshing the data in your UITableView, check out my suggestion on this thread:
Fails to call delegate/datasource methods in UITableView implementation
I'm not sure if this is a quirk with iOS 8, but I've had a few occassions where just setting the table's dataSource and delegate in the code hasn't been enough.
After you get your response and populate dataSource just call
[self.tableView reloadData];
Just set the data-source and delegate of table view in the delegate of the web-service delegate or where you get the response and reload the table view.

UITableView does not repopulate with reloadData

I have a UITableView that successfully populates with a NSMutableArray. However, when I try to use a search function that I have implemented, the UITableView does not repopulate at all.
The NSMutableArray also contains the correct number of objects according to the search but when realoadData is called, the numberOfSections and numberOfRows methods are called, but the cellForRow method is not (even though the search returns 1 item). The delegate and datasource for the UITableView are correctly set up and connected using IB.
I am happy to paste some code, but I am unsure as to what relevant code would be helpful in discussion here.
Thanks
Answer: Just me being stupid and using a saved NSArray rather than the updated NSMutableArray to populate the table. Silly me...

reloadData seems to work but doesn't show any cell on asynchronous search on tableView

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?

ASIHTTPRequest async updating uitableview

I'm using a UITableView which loads data from a server. I need to use async ASIHTTPRequest, which is in a separate .m.
How could I force to reload the table data when the requestFinished:request is called?
Thanks!
You can just send the data that needs to be loaded into the TableView by passing it between files. and then finally call a different method of inside the table view that implements the command [self.tableview relaodData];
Update:
What i see from your comments is that the you have a tableView CONtroller or someform of controller that loads the data by calling another class that holds the ASIHTTPrequest/ ansynchrinous requsts. now You have also told me that the TableView Also hold a UIViewController in each cell which i Dont think is a good idea you could go with a custom cell method have a look at this 4 part tutorial... now and the data that needs to be loaded into the TableView is loaded by TableViewController by some method wither it be each cell or something... so after you are able to get the data just inside the tableViewController just Call the [self.tablebview reloadData] inside the TableViewController which is the parent of the TableView there is no need to call in the other methods.
Finally solved with observers although when the app is completely closed won't work. I'll think in something.
Thanks

Resources