UIwebview delays loading - iphone

I have Login screen and second view which will be shown after login. On second view I have UIWebview which loads the url.
After login first it shows the empty view and slowly it loads the url. I want to show login screen with wait cursor, until the uiwebview loads the url and then want show that screen.
Can any body please provide code or sample for this?
Regards,
Malleswar

I cannot write your application for you, because it is a large project.
However, you might think about making your own login UIView as a child view of a UIViewController, which contains form elements:
This view controller is the root view controller in a UINavigationController stack.
The user enters her credentials into this form.
On clicking Submit, you push another UIViewController on to the navigation stack that contains a UIView child, that itself has a UIProgressIndicatorView and a UIWebView as children views.
The progress indicator view does its spinning wheel thing while the web page loads with the user's credentials entered in step 2.
Once the web page finishes loading, it fires its delegate method telling you loading has finished. This delegate method tells the progress indicator view to stop spinning and hide.
I would recommend reading up on UINavigationController through Google and Apple's ample documentation and sample projects. One sample project template is included in Xcode, as well.

Related

Xcode - Manually load a view controller

What I am asking may be impossible and sound weird, but here it goes.
Here is similar to what I want to achieve:
A user opens the app for the first time, there are two tab bars, in the first one (he has not tapped the second one yet) he presses a button that should initiate a progress view and text view changes and other view changes EVEN THOUGH the user has not loaded the other view controller by clicking the second tab bar.
So, is there a way to generally load a view controller before the user manually loads it himself, I know calling viewDidLoad manually will not help, any suggestions? Pretty confusing, it is like modifying a view but the controller has not loaded yet...
Thanks!
Make the changes in the other view controller and then let the controller configure its own view when it does its natural loading.

Reload View only when application is opened Again

My application has tab bar with one of the tabs having a segmented control on navigation bar.
Based on segment clicked different view is displayed using a url.
I am calling the url in viewdidload method.I do not want to use viewwillAppear to call the url as it will be called each time the view is displayed.
I only want to call the url again whenever user closes the application and comes back.
Whats the best way to do this.Should I remove the view controller from and reload it again once the application is opened.
Please use a more descriptive title for your question next time!
There are notifications for this that you can observe in your application:
UIApplicationDidBecomeActiveNotification and UIApplicationWillEnterForegroundNotification come to mind.

Present login screen on app startup

In my previous question on UIView animations I mentioned that I have to simulate the modal behavior for some view. Here I'll explain why and ask about some better solution.
The first view a user should see in my app is the login screen. Upon successful authentication the program checks if the user is a parent or a child (in a family). For each of these roles the app must provide different functionality.
So I designed the app like this:
Declare outlets for the login view controller and a tab bar controller (for the main part of the interface) in my AppDelegate.
In the application:didFinishLaunchingWithOptions: method
Set the rootViewController of the main window to the login view controller.
Make AppDelegate the delegate for the login controller, so it can send notification when it's done its job.
When AppDelegate receives the message on successful login, it determines whether the user is a parent or a child, instantiates the set of view controllers that provide corresponding functionality and passes them to the tab bar controller.
At last AppDelegate switches the rootViewController of the main window to the tab bar controller.
Certainly the user can logout, then the rootViewController is switched back again to the login controller.
I would like to present and dismiss the login screen as if it is a modal view, but AppDelegate only has a bare window, thus I don't have an object to send presentModalViewController: to. This brings up a question:
First of all, is it a good design?
And if it is, how do I simulate a modal behavior correctly?
I think you're on the right track.
However, I always try to get out of the app delegate as soon as I can, leaving it only to do application-level things (like respond to notifications, go in and out of background). In this case, doing so will help you.
In the appDelegate, create a new UIViewController class, something like "startUpController".
Add it's view to the app window.
Then in your startUpController, do everything that you used to do in the app delegate (login, tab bar setup, etc.).
And now, since you're in a view controller, you can presentModalViewController to your hearts content.
Hii,
you should refer this
http://code.google.com/p/tweetero/
https://github.com/jbrien/WordPress-iPhone
Hope this helps!

Loading the content of a UIWebView before displaying it

I have a set number of ViewControllers in my app. They are allocated and initialized at application launch and released at exit. They are used by a NavigationController to be pushed/popped. In these ViewControllers there are WebViews (actually there is nothing else).
My problem is :
When I want to change de content (URL) of a WebView that is not on the current TopViewController, the content isn't loaded until I push/pop the associated ViewController.
And the transition us "ugly". The pushed/popped Viewcontroller shows old content at worst or blank page at best, before the ViewController is in full view THEN the new content is shown.
I tried lots of things (even putting the "loadRequest" in a different thread with looks stupid).
Do you know any way to make things go smooth?
In general you should plan your UI for slow UIWebView loads, because you can't plan ahead to know how long things will take. What I often do is have a UIView that has a spinner and a message such as "Loading..." that is layered on top of the UIWebView. Here's how I use it:
In viewWillAppear: I unhide the loading view and start the spinner.
In webViewDidFinishLoad I hide the loading view.
If webViewDidFail gets called, then you're not showing some interim or invalid content while the page loads. You can present a UIAlertView in that case.
If you're curious, you can see this in the high score page of my game (Lexitect, free)

iphone - how to mentain the state of UIWebView?

i am having a UIWebView showing and HTML page that has some checkboxes, radio buttons. My Application has tabbar controller that switches b/w two controllers. How i can maintain the current state of UIWebView. ( e.g. i have selected a checkbox and i change the tab and go to other ViewController and again come back to UIWebView. the WebView resets itself and goes to the start... i want to maintain the state of UIWebView ( all the checkboxes clicked) .. how i will do that ??
any idea ??
thanks in advance
It sounds like you're loading your web view in viewDidAppear:, or some other method that gets called each time you switch to the tab. If you load your web view in viewDidLoad:, it will only get loaded once, and will retain its state when you switch tabs.
EDIT: When I wrote this answer back in 2009, I apparently didn't understand the view controller life cycle as well as I thought I did. Corey Floyd was right. The viewDidLoad: method can also get called multiple times, because UIViewController will unload its view in low memory situations if the view isn't being displayed. When the user switches back to the view, viewDidLoad gets called again to reconstruct the view.
How embarrassing.
I have an idea that might help:
to get the status from your app to the webpage, give the variables' values as request parameters with the called URL and let the webpage handle them and view the form elements accordingly.
to get the status from the webpage back to your app, let the webpage be refreshed each time any of its element is updated, and with the new URL give the new values of the changed elements. Back to your app, you can implement the UIWebViewDelegate and inside the method WebViewDidFinishLoad (or WebViewDidStartLoad as you prefer) use the webView.request.URL to parse the GET parameters and update your app accordingly.
hope this will help.