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

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.

Related

UIWebView's shouldStartLoadWithRequest doesn't called sometimes

I am using a UIWebView in my app and I am overriding the shouldStartLoadWithRequest message to detect what kind of link is being clicked. If it's a "special" link, I push a UIViewController onto the stack and return NO from this method. This works just dandy most of the time.
Sometimes, however, I click on a link and my shouldStartLoadWithRequest never gets called. Now what's weird is that the UIViewController which houses the UIWebView is in a UITabBarController and when I click on another tab, the UIWebView finally gets its shouldStartLoadWithRequest called. Until I click this other tab, I do NOT get a call to shouldStartLoadWithRequest. The other interesting bit is that the failure case never happens the first time I click on a link; it's always on a subsequent time.
Has anyone seen this? To me, this sounds like the UIWebView is, sometimes, not getting a touchEnded event and by switching tabs, the underlying framework is forcing a touchEnded event which in turn causes my shouldStartLoadWithRequest to get called.
Are you implementing the
– webView:didFailLoadWithError:
method from the UIWebViewDelegate? Perhaps you're getting an error on the request and then you're never seeing it? This delegate should get thrown when you have issue such as timeouts and other things.

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

(iphone) show custom activity indicator?

I've made a custom activity indicator (actually just an imageView)
When user clicks something and I expect it will take a bit long to process(alloc a UIViewController and push on to navigation stack),
I alloc the indicator and add it as subview of current view just before the lengthy process starts.
Strange thing is, indicator doesn't show up until the push (left-right) animation starts.
Is it because the lengthy job takes the system, and ui drawing for activity indicator is delayed?
Am I doing something wrong here?
Thank you
Edit
Looks like I can do the "push" in background.. i'm trying it now
IPhone SDK - Leaking Memory with performSelectorInBackground
Is your job synchrone or asynchrone ?
If it's the first case, then it can be the problem.
Check all the method like :
[ self performSelector:<#(SEL)aSelector#> ];
You can thread this to avoid your [potential] problem.
Good luck.
You should process your lengthy tasks in the background. The UI won't update if you block the main thread.
So you have to refactor your app, the alloc and push of the viewController should happen within the blink of an eye, because you can't do this in the background.
But you can do the processing (downloading data I guess) in the background.
There is plenty information available about background processing. The way to go varies heavily on what you want to do exactly.

Application freezes for some time

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.

UIWebView/MPMoviePlayerController and the "Done" button

I am using the UIWebView to load both streaming audio and video. I have properly set up the UIWebView delegate and I am receiving webViewDidStartLoading and webViewFinishedLoading events perfectly. The webview launches a full screen window (likely a MPMoviePlayerController)
Apple's MoviePlayer example gets the array of Windows to determine which window the moviePlayerWindow is for adding custom drawing/getting at the GUI components. I believe this to be a bad practice/hack.
My expectation is that I should be able to figure out when that button was clicked by either a delegate method or an NSNotification. It may also be the case that I have to poke around subviews or controllers with isKindOf calls, but I don't think those are correct approaches.
Are my expectations incorrect, and if so, why?
What is the correct way to bind an action to that "Done" button?
There isn't an MPMoviePlayer instance method that covers this. You can use - (void) moviePlayBackDidFinish:(NSNotification*)notification to find out when the movie has finished. Or you could overlay the existing Done button with your own and have complete control that way.
You can also use MPMoviePlayerWillExitFullscreenNotification in order to conrol the action provided that youe MoviePlayer is in fulscreen mode.