I am using XCode 4.0.1. I have to different views with UITableView. Data is coming from server. I am parsing JSON data and displaying it to tableview. I am using reloaddata method to display data on tableview. But mostly It is not displaying anything(It is not calling tableview delegate methods) but sometimes functioning normally. I am calling URL at ViewWillAppear, calling reloaddata on connectiondidfinishloadingdata.
I am experienced programmer for iphone but this is unexpected to me. Any Suggestions. Thanks in advance.
May be you should call your update on the main thread.
Related
Summary of the issue:
When I am loading some data into my iPhone application from a webservice, it populates the tableview two times with double number of records. I found that Viewdidload method is called two times causing this issue.
Scenario
From the first view I parse the webservice and collect the data into an array object.
This array object is being used by the second view to populate the tableview.
I am wondering what is behind reloading of the page causing the tableview has double number of records. Hope somebody can give me a hint.
You may want to consider calling applicationDidFinishLaunchingWithOptions in your app delegate, as this is only called during launch.
Thanks for the tips. What I found the issue was the way adding the view. i replaced [self.view addSubview:trlist.view] with [self presentModelViewController:trlist animated:NO]; and now it loads only one time.
Very new to programming for iOS and Cocoa so please take it easy on me as I try to wrap my brain around the following. I'm trying to display a tableview populated from an XML feed as the opening screen of my app. I've tried to consume the XML from inside my AppDelegate using the ApplicationDidFinishLaunching method (and then making my AppDelegate a delegate for the XML parser which I access using a NSUrlConnection and its delegate methods) but I can't figure out how to take the parsed XML file and pass it to a tableviewcontroller which can then use it as the datasource for a tableview. When I do try, I always get a blank tableview.
I've written the code a few times and nothing seems to work.. I'll post what I have here to show what I've got so far but I'm afraid its mostly vanilla AppDelegate with a few parser methods thrown in.. any pointers in the right direction would be super appreciated.
Thank you in advance!
Hmm, probably a bad idea to do the network call in the AppDelegate. Try to put all that code at the view controller level. Here's a brief structure of what I do (Since it's very similar)
View Controller listens to button events
Use ASIHTTPRequest to talk to your web service. Handles network really well, you can skip the NSURLConnection stuff.
Try to load your data source (an array?) with static values and see if they come up on the table view.
Parse the response from ASIHTTPRequest using NSXMLParser, and load the data you want into the static array you were using. More here.
Call [tableView reloadData] once you're done and the changes will reflect.
Did you specify a UITableViewDataSource for your table view and implement the two required methods?
tableView:cellForRowAtIndexPath:
and
tableView:numberOfRowsInSection:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html
When I get blank tables, this is what it is; I've forgotten to specify the data source
In my UIView I've got a UITableView (UITV) which is controlled by an NSFetchedResultsController (NSFRC). The UIView is inside a UINavigationController.
When the view is about to be loaded/displayed I start some background activities which fetch data from a remote server (JSON) and parse into Core Data.
The NSFRC is being called when the parsing is done and the threaded NSManagedObjectContext have been merged into the main context.
The problem is that sometimes many rows are being inserted to Core Data at once, a lot of table cells are being added and there is quite a delay from that the actual fetching and parsing is done, until the rows are being displayed.
Now I wonder if anyone knows of any solution to, for example:
hook up a spinner to some "fetched results controller inserted all its rows for this time" (or something) notification/delegate call to at least tell the user that "something is going to show up soon"?
Or might the best solution simply be to not initialize the NSFRC until the background fetching and processing is completed?
Thanks!
If I understand your question correctly, you may want to look into the NSFetchedResultsControllerDelegate methods, with documentation available here: http://developer.apple.com/library/ios/#documentation/CoreData/Reference/NSFetchedResultsControllerDelegate_Protocol/Reference/Reference.html
There are delegate methods available for pre changes with controllerWillChangeContent:, post changes with controllerDidChangeContent and during changes with didChangeSection: and didChangeObject.
I hope it helps!
Rog
I am trying to load a table view from a cache very quickly and have the cached data in the table view appear. Then I want download new data, and then reload the table. Right now I am downloading the new data on viewDidAppear, but the view still refreshes before it displays. Any idea how I can do this?
viewDidAppear is not a good place to download data; it is really intended for clean up after presenting data, so I can understand why you used it. You should request your data reload as early as possible, such as in viewDidLoad or viewWillAppear (depending on your reuse or otherwise of view controllers).
If you are doing asynchronous downloads, which you should be, put the reloadData call in your delegate callback function for when the data is completed.
Simply calling [tableView reloadData] after the download might do the trick. This will trigger a refresh of your table cells.
To download the new data, you may consider using Cocoa Streams, particular an asynchronous Socket Stream. In the stream delegate, call reloadData when the download is completed.
I ended up implementing the delegate class to do this asynchronously. This example was extremely helpful, and I implemented much of its code:
http://developer.apple.com/iphone/library/samplecode/URLCache/Introduction/Intro.html#//apple_ref/doc/uid/DTS40008061-Intro-DontLinkElementID_2
I need help getting dataSource in OpenFlow. I
I want to provide CoverFlow functionality whenever the phone is turned horizontally. I'm using Alex Fajkowski's awesome code OpenFlow ( http://fajkowski.com/blog/2009/08/02/openflow-a-coverflow-api-replacement-for-the-iphone/ ) but the example provided is very different than what I need.
I am using OpenFlow in a horizontal view inside a navbar view controller. I have OpenFlow working already. I can scroll through all my images and works really good. However I am using it with over 100 images and it takes a while to load at first. In looking into performance improvements I realized the AFOpenFlowViewDataSource delegate is not getting called. I was able to get AFOpenFlowViewDelegate working by specifying the delegate in the view controller class "flowView.dataSource = self;". But I am not able to get the datasource delegate working. Not even with "flowView.viewDelegate = self;".
Is the datasource needed at all? It seems it is needed for threading of loading.
Ok, it looks like it is running beautiful now. The DataSource delegate is only called when there the objects are loaded dynamically. Meaning, if I use "[(AFOpenFlowView *)self.view setImage]" then dataSOurce is never called because all it knows images are already loaded. However, using "[(AFOpenFlowView *)self.view setNumberOfImages:30];" triggers the DataSource delegate to load the images as they are needed. I found the GetImageOperation NSThread very useful for my 100+ images. However, images are not unloaded after going offscreen. Anyone know how to unload images as they go off screen?