Application freezes for some time - iphone

In my app I have a login view. When I enter login details and click login button, the app freezes for some time and then continues. I know it's freezing because it is communicating with remote server but how can I prevent the freeze thing and show a nice looking status animation instead?

As you are communication with server it will takes some time, so meanwhile you can add some animation on alertview.
But by calling simply alertview it will not work.
So you have to proceed in the following steps:
1) On Submit Button Click first add Custom Indication View
2) Start Animation View
3) Call NSThread for server communication like
[NSThread detachNewThreadSelector:#selector(yourActionName) toTarget:self withObject:nil];
4) Remove Animation View
For more information go through this article:
http://iphonedevcentral.blogspot.com/2010/08/safe-threaded-design-and-inter-thread.html

Your API call is blocking the GUI thread. You can circumvent this by moving the remote API request call in a NSOperation call, and pop up a loading screen until the API call returns.

Related

Spinning reload button such as the one found in Path 2.0?

I'm attempting create a spinning reload button, such as the one found in the new Path app.
It's for a UIWebView, and should behave in the following way:
upon touchupinside, it should reload the webview and spin while it reloads.
while it's spinning, another touchupinside should stop the reloading of the webview.
upon completion of the reload, it should stop spinning
it should be a subview of UINagivationController
Can a kind individual point me in the right direction or link me to a tutorial on something like this? I've searched around and there doesn't seem to be anything similar. Thanks!
The UIActivityIndicator class will give you the functionality you need. Use startAnimating and stopAnimating along with hidesWhenStopped. Documentation is here: http://developer.apple.com/library/IOs/#documentation/UIKit/Reference/UIActivityIndicatorView_Class/Reference/UIActivityIndicatorView.html
To use this with your UIWebView, you can place the calls to the UIActivityIndicator in the UIWebViewDelegate methods.
In webView:shouldStartLoadWithRequest:navigationType: you should return YES, and start the activity indicator. In didFailLoad and didFinishLoad you can then stop the activity indicator.
Finally, for your touchUpInside behaviour, you can send the following messages to your UIWebView, reload and stopLoading.
An alternative would be to call the UIActivityIndicator's methods at the same time as calling reload and stopLoading.

IBAction - do something before connect to server

I have an IBAction, triggered by a UIButton.
In this IBAction I connect my app to server, returning a Plist.
During this time (between my apps connect to server, and the server returns that Plist) I want to show a UIActivityIndicator.
The problem is, when my IBAction is triggered, the apps connect first to server, an then shows the UIActivityIndicator.
My IBAction in pseudocode
- (IBAction) loginMe: (id) sender
{
// show activity indicator
// connect to server, and catch data
}
Your "connect to server" action is likely synchronous. The action "show activity monitor" is incorrectly labeled. What you're really doing is "mark activity monitor for display next time drawing occurs."
What you need to do is to make sure that loginMe: returns so that the UI can update. The server connection logic needs to continue asynchronously. Generally this is done with NSURLConnection. You can find explanation in the URL Loading System Programming Guide.
Also check out MBProgressHUD here:
https://github.com/jdg/MBProgressHUD
It wraps the indicator and allows for additional customization based on how you connect synchronously or asynchronously.

can any one tell me the name of alert view that should do the works of **C# show dialog**

can any one tell me the name of alert view that should do the works of C# show dialog .
other actions will not work without dismissing it(EVEN DELEGATES ALSO).
Modal dialogs in Windows (in any language) and in iOS are fundamentally different.
On Windows, a modal dialog (and in particular the ShowDialog method) behaves like a function call that will only return when the dialog is closed. Your app will naturally wait until the your has made his decision.
On iOS, presentModalViewController (or [UIAlertView show]) almost immediately return. You can registered a delegate that will be notified when the dialog is closed. But if your app is supposed to wait only the user has chosen something in the dialog, then you have to implement the waiting yourself.
As far as know, You have to do this manually. You can lock your task when the alert is shown and then unlock it again when it is dismissed getting help from these posts.
is there a way to pause an NSTHread indefinitely and have it resumed from another thread?
How to pause an NSThread until notified?

I want eject any user action until a function is done, iphone app!

i'm writing an iphone app integrate with webservice.When user wait to login on web,I want eject any user action until login is done. Please help me! thanks!
One way would be to pop up a modal view controller using presentModalViewController. Another way would be to use [[UIApplication sharedApplication] beginIgnoringInteractionEvents]
If you don't multithread your code the user shouldn't be able to interact with your UI while you're getting and sending data.
Alternatively you could present a semitransparent loading screen over the whole UI -while loading- that intercepts every touch event.

UIAlertView inside an NSOperation is not modal in iPhone

So I am trying to create a check that tries to connect to the WWW. when it fails it needs to then retry several times before the application gives up and quits. Each time it retries the user is propted with an UIAlertView with the options to Retry or Cancel.
So here is the problem.
I have a chain of actions in an NSOperationQueue, all the operations should fail with no connection. I"m using the NSoperation Queue so that the UI dosn't lock and the data is being processed in the background.
inside an NSInvocationOperation my method will hit [AlertView show], however this is not truly modal.
My operation then returns and continues through the chain of NSOperations, as there seems to be no way to return them with an Error value to stop additional processing. Eventually the UI catches up, displays the Modal AlertView, but i have no context of what has happened.
I am sure this is a common requirement. any ideas how to achieve this?
If I understand you correctly, you want a modal version of UIAlertView, but only modal within the calling thread/NSOperation? A few problems with this:
You should probably only call interface operations from the main thread (easily addressed using performSelectorOnMainThread:)
Modal dialogs are not really part of the OS; you'll need to address this programatically.