Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-07-2012, 06:17 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 47
at0m87 is on a distinguished road
Default How to unload a view?

In my WebViewController, there is a UIWebview.

i wrote in the activity code to show the spinning wheel while the webpage loads:

Code:
-(void)showWebView{
    NSURL *url = [NSURL URLWithString:loginObj.loginURL];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [myWebView loadRequest:request];
    
    timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(spin) userInfo:nil repeats:YES];
    
}

//--activity indicator to show the loading of webpages
- (void)spin{
    if (!myWebView.loading){
        [activity stopAnimating];
        NSLog(@"Stop Spinning");
        
    }
    else{
        [activity startAnimating];
        NSLog(@"Spinning");

    }
    
}
The method is still running even though i have exited the view as the debugger is printing "stop spinning" endlessly. How do i stop this method from running when i exit from the view with the UIWebView?
at0m87 is offline   Reply With Quote
Old 02-07-2012, 07:09 AM   #2 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Helsinki
Posts: 304
fiftysixty is on a distinguished road
Default

Quote:
Originally Posted by at0m87 View Post
In my WebViewController, there is a UIWebview.

i wrote in the activity code to show the spinning wheel while the webpage loads:

Code:
-(void)showWebView{
    NSURL *url = [NSURL URLWithString:loginObj.loginURL];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [myWebView loadRequest:request];
    
    timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(spin) userInfo:nil repeats:YES];
    
}

//--activity indicator to show the loading of webpages
- (void)spin{
    if (!myWebView.loading){
        [activity stopAnimating];
        NSLog(@"Stop Spinning");
        
    }
    else{
        [activity startAnimating];
        NSLog(@"Spinning");

    }
    
}
The method is still running even though i have exited the view as the debugger is printing "stop spinning" endlessly. How do i stop this method from running when i exit from the view with the UIWebView?
The particulars of how to stop depend on your implementation details. However, a better place to put the stopAnimating call would in in the webViewDidFinishLoad-method.

Another issue is that your if-clause is problematic: if ( !myWebView.loading )

If we look at it in more detail, what happens if myWebView is nil? Then myWebView.loading is also nil, and the clause evaluates to true. That coupled with the fact that you're not stopping the NSTimer is most likely causing the behavior you're witnessing. If you put the stopAnimating call into webViewDidFinishLoad, you can get rid of the NSTimer and also get rid of this problem altogether.
fiftysixty is offline   Reply With Quote
Old 02-07-2012, 09:17 AM   #3 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 47
at0m87 is on a distinguished road
Default

Quote:
Originally Posted by fiftysixty View Post
The particulars of how to stop depend on your implementation details. However, a better place to put the stopAnimating call would in in the webViewDidFinishLoad-method.

Another issue is that your if-clause is problematic: if ( !myWebView.loading )

If we look at it in more detail, what happens if myWebView is nil? Then myWebView.loading is also nil, and the clause evaluates to true. That coupled with the fact that you're not stopping the NSTimer is most likely causing the behavior you're witnessing. If you put the stopAnimating call into webViewDidFinishLoad, you can get rid of the NSTimer and also get rid of this problem altogether.
Thanks fiftysixty for answering my question again. Thank you for your suggestion, now i put
Code:
[activity startAnimating]
in the method which loads the UIWebView and put the
Code:
[activity stopAnimating]
in the webViewDidFinishLoad method as suggested by you. Now the Activity indicator works the same but without the unnecessary timer!

cheers!
at0m87 is offline   Reply With Quote
Reply

Bookmarks

Tags
activity indicator, exit, uiwebview, unload, view

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 412
17 members and 395 guests
Alex-alex, Apptronics RBC, baja_yu, dre, FrankWeller, gwelmarten, ipodphone, jeroenkeij, jleannex55, matador1978, n00b, pbart, reficul, Retouchable, Sami Gh, usernametaken, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,125
Posts: 402,910
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:18 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0