views:

148

answers:

3

I am creating a tabbar application. One of the tabs is for an rss feed, which is a navigation application. but when i click the tab bat button, it is taking a while to load the view of that tab. It is because the application is waiting for the feed to be loaded from the server. Is there any way to load the view before the loading of that feed takes place. As of now, i'm giving the request in the viewDidLoad method. Thats what is creating the problem. To which part shall i move the code so that the view is loaded instantaneously when clicking the tabbar button.

+1  A: 

I recommend this great article on this subject on iCodeBlog, it's a very elegant way of doing this. If you submit your rss feed loading as an NSOperation, it will take place nicely in the background without blocking your main thread.

Zoran Simic
is there any other method than NSOperation?
Nithin
is there any reason why the recommended way of doing this won't work for you?
deanWombourne
the tutorial given there is loading the feed on a button click whereas i need to load that automatically..
Nithin
The loading is triggered by a call to loadData - this doesn't have to be from a button, just call it when you want - i.e. in your app delegate just call [self loadData]; ?
deanWombourne
Yes, this can be called anywhere you want, on a button press or automatically, it's up to you. You can do it in your 'loadData', or 'viewDidLoad' function or even in 'viewWillAppear'
Zoran Simic
There are other ways than NSOperation, but I found the NSOperation way to be very elegant and simple. You said that part of the problem is that it "takes a while to load the view of that tab". That sounds like what you need is perform the lengthy load operation in a separate thread. I think using the NSOperation method is by far the simplest for you.
Zoran Simic
A: 

I also think that the problem is more that you don't use the HTTP request asyncronously (as Apple recommends). See this document. http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html

It worked for me in my applications.

bartvdpoel
+1  A: 

use:

[self performSelector:@selector(performRSS:) withObject:<nil afterDelay:0.3f];

or

[NSThread detachNewThreadSelector:@selector(performRSS:) toTarget:self withObject:nil];

and place RSS feed related code in a separate function named "performRSS".

Manjunath