Web view is loading after the transition animation - iphone

i am using a web view and alsousing the drag event to load next or previous page on drag right or left event simultaneously but the web loads the next page after fininshing the curl up animation.
i want to load page data during the animation,
it takes one second to load the new page after animation finishes.
i have checked the loading timing and sequence, web view is loading page and finish loading before starting animation but curlup animation is actually locking the page.
can any one please help me.

You might try to load the next and previous pages on a background thread, so they will be already loaded when the user tries to reach them...
U might want to create an method to get the views (Eg.getView) that takes an NSURL as argument...
and for every swipe you call:
NextView= [self performSelectorInBackground:#selector(getView:) withObject:nextURL];
PrevView= [self performSelectorInBackground:#selector(sgetView:) withObject:prevURL];

Related

synchronously load html content in UIWebView

im using a UIWebView to show html content in my app, the app contains two arrows to navigate between topics just like a RSS reader app, but when the user hits up or down arrow, the next topic doesn't show up until the data come back and the user still able to interact with the UI which is a bit confusing,
My question: how to block the UI when user moves to the next/back topic ? in other words how to make loadHTMLString:baseURL: works as a synchronous calling ? thanks !
You can let the load happen asynchronously, but set the web view's userInteractionEnabled property to NO. (then back to YES, on the didFinishLoad callback).
Or you could put up a clear colored view (with userInteractionEnabled set to NO) above the web view that has an activity indicator and button that lets the user cancel the load.
An even better idea would be to place two other web views offscreen and start loading them for page N-1 and N+1. When the user presses a page arrow, swap frames with the corresponding prefetched web view.
Try this - https://github.com/gavrix/UISynchedWebView-demo
You don't actually want to block the UI. If you do that, there is a very high probability that Apple will reject your app once you send it in for app store submission. Anything that even remotely makes the application feel unresponsive will weigh heavily on you. Instead, create a background thread using GCD or performSelectorInBackground, handle your loading in that, and then once the loading is done, make all of the information available to your UIWebView all at once and alert it to render the display.
If you are in a pinch and have a UIPageViewController and still want to use a UISynchedWebView to ensure that a page has loaded before you run javascript, you can run a block on the main thread's event queue. Still has a slight delay while the javascript runs but won't cause recursion in the run loop.
dispatch_async(dispatch_get_main_queue(), ^{
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://google.com"]]]; // self.webView is a UISynchedWebView
NSLog(#"url:%#", [self.webView stringByEvaluatingJavaScriptFromString:#"window.location.href;"]); // shows google.com instead of about:blank
});

UIActivityIndicator while loading data into UITableView

I have a UITableView which loads its data from the web. It takes a while to load this data and therefore I would like an acitivity indicator to animate while the data is loading. I am doing the following in my attempt to make this work:
1) In viewDidLoad I add an observer to listen to when the data loading is done and after that I call loadDataFromWeb
2) loadDataFromWeb creates the activity indicator, adds it as a subview to self.view and then it loads the data. At last it posts a notification (the one that viewDidLoad observes) to indicate that the loading process is done.
3) Finally, when the observer catches the post from loadDataFromWeb, it calls removeLoadingScreen to remove the indicator.
Pretty obvious I am not seeing my indicator view. If I comment out the line that removes the indicator, it stays on the screen when everything is loaded. I am aware that I'm probably messing around with which methods are called when in the process, and this is where I need help.
I should mention that the whole purpose is that instead of the user's looking at a screen on which nothing is happening (while the data loads), I want a activity indicator to show up to indicate that there's something going on here.
Thanks
#Muncken have a look at this MBProgresHUD project, this will help you a lot to do a downloading progress in background (secondary thread not main thread) and shows a activity indicator over you view -
https://github.com/matej/MBProgressHUD

Have can I show a progresss indication when I'm doing my work before the tableview is loaded?

I allow the user to manage records on other views. I set a flag if certain changes are made.
Then on the flag (where the data changes will have an impact) I run some methods / queries which create the data which is used in my table view(s). This workload currently happens in viewWillAppear(s).
This could take a few seconds and I'd like to show my progress indicator view which I wrote today, it uses a transparent view with a activity indicator in the center of the view.
[self performSelectorInBackground:#selector(startupStuff) withObject:sender];
However, viewWillAppear won't wait while I run the the work in the background.
Ideally I'm looking for a quick fix to work around this problem.
Any ideas ?
However, viewWillAppear won't wait while I run the the work in the background.
That's the whole point of it, isn't it? At the end of your startupStuff method, you should call another method on the main thread (with performSelectorOnMainThread:...) that is used to (a) inform the controller that your data is ready, (b) reload the table view and (c) dismiss your progress indicator view.

Execute a function just after the view loads, iphone

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.
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.
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".
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.

UIActivityIndicatorView with UITableView in Navigation Controller

I am working on a an application which is very simple
a navigation controller with a table view
when the user clicks a row, he is directed to the details view.
However, the details view pulls data from Core Data. i am pulling a relatively large amount of data that takes about three seconds to load.
I wanted to add that UIActivityIndicatorView to show progress.
I tried to start the animation once the user clicks the row, so i set it to animate in didSelectRowAtIndexPath
For some reason, the Activity Indicator doesn't start before the pushing of the details view.
Any idea why? or the best way to implement such an idea?
~Adham
Because you start the animation and then start a large operation in the same thread. Consider running that 3 second operation in a new thread. Look at NSOperationQueue and then create a NSOperation to run that procedure. It will work this way.
The UI doesn't update until the end of your run loop. You are, in sequence, displaying the activity monitor, then pushing the new table view, and then the UI updates. You need to change this order.
You can either move something to a different thread, or you could perhaps delay the loading of the new table view by calling performSelector:afterDelay: with a delay of 0. That will delay the loading of the new table view until after the activity indicator appears in the UI. Now, it's still all on the same thread, so you will be blocked from doing anything, but if the animation is threaded in the activity monitor, it would make for a quick and easy solution.
Call method in thread:
[NSThread detachNewThreadSelector: #selector(loadMethod) toTarget:self withObject:nil];
See following for more details:
http://iphone.zcentric.com/?s=UIActivityIndicatorView