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 09-07-2011, 05:53 PM   #1 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 33
justinwhite1 is on a distinguished road
Default Remove Custom Activity Indicator

Hi All! I have my custom indicator loading, but now I'm having trouble removing it. Should I place something in viewDidLoad? Attached is my code. Thanks
Code:
- (void)viewDidLoad 
{	

    
   UIImageView *customActivityIndicator = [[UIImageView alloc] initWithFrame:CGRectMake(50,50,190,12)];
    customActivityIndicator.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"status1.png"],[UIImage imageNamed:@"status2.png"],nil];
    customActivityIndicator.animationDuration = 1.0; // in seconds
    customActivityIndicator.animationRepeatCount = 0; // sets to loop
    [customActivityIndicator startAnimating]; // starts animating
    [self.view addSubview:customActivityIndicator];
    [super viewDidLoad];
}
justinwhite1 is offline   Reply With Quote
Old 09-07-2011, 06:03 PM   #2 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

1. The call to superview in load methods should go first, then your code.
2. That code is loading and showing it. Where are you trying to remove it. I don't see you keeping a reference to it here, or at least setting a custom Tag so you can reach it later and remove it from the superview.
baja_yu is offline   Reply With Quote
Old 09-07-2011, 06:07 PM   #3 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by justinwhite1 View Post
Hi All! I have my custom indicator loading, but now I'm having trouble removing it. Should I place something in viewDidLoad? Attached is my code. Thanks
Code:
- (void)viewDidLoad 
{	

    
   UIImageView *customActivityIndicator = [[UIImageView alloc] initWithFrame:CGRectMake(50,50,190,12)];
    customActivityIndicator.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"status1.png"],[UIImage imageNamed:@"status2.png"],nil];
    customActivityIndicator.animationDuration = 1.0; // in seconds
    customActivityIndicator.animationRepeatCount = 0; // sets to loop
    [customActivityIndicator startAnimating]; // starts animating
    [self.view addSubview:customActivityIndicator];
    [super viewDidLoad];
}

Add a retained property to your view controller and set that property.

When you want it to stop animating, send it a stopAnimating message, and then set it's hidden property to TRUE.

Remember to release the property in your view controller's dealloc method. (self.customActivityIndicator = NIL)
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.

Last edited by Duncan C; 09-07-2011 at 06:25 PM.
Duncan C is offline   Reply With Quote
Old 09-07-2011, 06:18 PM   #4 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 33
justinwhite1 is on a distinguished road
Default webviewdidfinishload

I have a map that is populating. Once it is finished, I'd like to remove the activity indicator.

Code:
- (void)webViewDidFinishLoad:(UIWebView *)webView 
{
[customActivityIndicator setHidden:YES];
 }
justinwhite1 is offline   Reply With Quote
Old 09-07-2011, 06:22 PM   #5 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

1. Hiding is not removing it. Remove it from the superview and release it.
2. customActivityIndicator is locally declared in viewDidLoad, you can't access it from other methods. That's why you need a reference to it, create a property as Duncan said.
baja_yu is offline   Reply With Quote
Old 09-07-2011, 06:46 PM   #6 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by justinwhite1 View Post
I have a map that is populating. Once it is finished, I'd like to remove the activity indicator.

Code:
- (void)webViewDidFinishLoad:(UIWebView *)webView 
{
[customActivityIndicator setHidden:YES];
 }
If you're going to use it repeatedly, hiding/stopping it, then showing it/starting it is a good way to go.

If you're going to use it once and want to discard it when you're done with it, then you need to stop it from animating, remove it from it's superview, and release it.

I think I would probably create a custom object that did this stuff for me. I'd give it a show: method that took a boolean parameter. When true, it would set it's hidden property to true and start animating. When called with a value of false, it would stop animating and set it's hidden property to TRUE.

Once you've created a custom subclass of a UIView (or UIImageView) object, you can add it to a nib file, which is handy.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 09-07-2011, 06:56 PM   #7 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 33
justinwhite1 is on a distinguished road
Default

Still a little new to this. Attached are the issues I'm having.

Uploaded with ImageShack.us
justinwhite1 is offline   Reply With Quote
Old 09-07-2011, 06:58 PM   #8 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by justinwhite1 View Post
Still a little new to this. Attached are the issues I'm having.

Uploaded with ImageShack.us
Don't declare a new variable customActivityIndicator. Use the property.

Post that code if you want us to show you how to fix it. WE can't quote/edit an image.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 09-07-2011, 07:03 PM   #9 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 33
justinwhite1 is on a distinguished road
Default Code

Attached is my short code
Code:
    //

#import "ThirdViewController.h"
#import "MapViewController.h"
#import "LocationsMap.h"
#import "LocationController.h"
#import "Free_RX_iCardAppDelegate.h"
#import "XMLReader.h"
#import "JSON.h"
#import "DetailViewController.h"
#import "SFAnnotation.h"
#import "PharmacyListViewController.h"

@implementation ThirdViewController

@synthesize customActivityIndicator;
@synthesize locationController;
@synthesize reverseGeocoder;
@synthesize urlString;
@synthesize m_activity;
@synthesize webVw;
@synthesize mapView;
@synthesize searchbar;
BOOL isFromSearch = NO;


- (void)viewDidLoad 
{	
    UIImageView *customActivityIndicator = [[UIImageView alloc] initWithFrame:CGRectMake(50,50,190,12)];
    customActivityIndicator.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"status1.png"],[UIImage imageNamed:@"status2.png"],nil];
    customActivityIndicator.animationDuration = 1.0; // in seconds
    customActivityIndicator.animationRepeatCount = 0; // sets to loop
    [customActivityIndicator startAnimating]; // starts animating
    [self.view addSubview:customActivityIndicator];
}




- (void)viewWillAppear:(BOOL)animated;
{
	
    Free_RX_iCardAppDelegate *appDelegate = (Free_RX_iCardAppDelegate .............................
   [appDelegate release];   
}




- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (void)locationUpdate:(CLLocation *)location 
{
    isFromSearch = NO;
	MKCoordinateRegion region;
	MKCoordinateSpan span;
	span.latitudeDelta = 0.05;
	span.longitudeDelta = 0.05;
	
	region.span=span;
	region.center=location.coordinate;
..............................
    [self FetchtheDataWithLatLong:coordinate.latitude AndLong:coordinate.longitude];
	
}




- (void)locationError:(NSError *)error 
{
	NSLog(@"locationError");
}




- (void)showDetails:(id)sender
{	
	Free_RX_iCardAppDelegate *appDelegate = ................................
	[objController release];
	

	appDelegate=nil;
	[appDelegate release];
	[arrAddresses release];
	arrAddresses = nil;
}



- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
	searchBar.showsCancelButton = YES;
	searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
    [customActivityIndicator setHidden:YES];

}


- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
}

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
}





- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar
{
   searchBar.showsCancelButton = NO;
    [searchBar resignFirstResponder];
}





- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    isFromSearch = YES;
     searchBar.showsCancelButton = NO;
 	[searchBar resignFirstResponder];

	SFAnnotation *nextAnnotation;
	int index;
	for (index=[[mapView annotations] count] - 1; index>=0;index--)
	{
		nextAnnotation =[[mapView annotations]objectAtIndex: index];
		[mapView  removeAnnotation: nextAnnotation];
	}
	[self FetchtheData:searchBar.text];
}


- (MKAnnotationView *) mapView:(MKMapView *) mapView viewForAnnotation:(id ) annotation {
	
	if ([annotation isKindOfClass:[MKUserLocation class]])
		return nil;
	
	MKPinAnnotationView* customAnnotationView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil] autorelease];
.................................................................. 
	NSLog(@"completed viewForAnnotation");
    return customAnnotationView;
	
}


-(void)PlaceMarksOfMap
{
	@try
	{
		NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
		SFAnnotation *nextAnnotation;
		int index;
		for (index=[[mapView annotations] count] - 1; index>=0;index--)
		{
			nextAnnotation =[[mapView annotations]objectAtIndex: index];
			[mapView  removeAnnotation: nextAnnotation];
		}
		
		NSLog(@"started map");
        Free_RX_iCardAppDelegate *appDelegate = (Free_RX_iCardAppDelegate *)[[UIApplication sharedApplication] delegate];
    
		NSMutableDictionary  *DictonaryMap = [[[NSMutableDictionary alloc]initWithContentsOfFile:[appDelegate PathForFile:@"result.plist"]] autorelease];
		id dictMain = [DictonaryMap objectForKey:@"UNA"];
		NSMutableArray *arrAddresses;
		
		if ([dictMain isKindOfClass:[NSArray class]]) 
		{
			arrAddresses = [[NSMutableArray alloc]initWithArray:dictMain];
		}
		else if([dictMain isKindOfClass:[NSDictionary class]])
		{
			arrAddresses = [[NSMutableArray alloc]initWithArray:[dictMain objectForKey:@"UNA"]];
		}
.............................

		[pool drain];
	}
	@catch (NSException * e) {
		NSLog(@"placeholder  %@",e);
	}
	NSLog(@"completed map");
  
}


- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
{
	[self performSelectorOnMainThread:@selector(showAndHideActivityIndicator:) withObject:@"YES" waitUntilDone:NO];
	NSLog(@"MKReverseGeocoder has failed.");
}








- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{

    isFromSearch = NO;
	NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
	[prefs setObject:placemark.postalCode forKey:@"zipcode"];
	[prefs synchronize];
	[self FetchtheData:placemark.postalCode];
}	



-(void)FetchtheData:(NSString *)strzipcode
{
	Free_RX_iCardAppDelegate *appDelegate = (Free_RX_iCardAppDelegate *)[[UIApplication sharedApplication] delegate];
.........................................
	appDelegate=nil;
	[appDelegate release];
       }


-(void)FetchtheDataWithLatLong:(double )Lat AndLong:(double)Long
{
	Free_RX_iCardAppDelegate *appDelegate = (Free_RX_iCardAppDelegate *)[[UIApplication sharedApplication] delegate];
	NSString *strtemp = [NSString ..............................
    {
        id dictMain = [dicttemp objectForKey:@"UNA"];
        NSMutableArray *arrAddresses;
.....................
withObject:nil waitUntilDone: YES];
	appDelegate=nil;
	[appDelegate release];
}




- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
	[webdata setLength:0];
}


- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{
    [webdata appendData:data];
    
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{
    [connection release];
	theConnection =nil;
	}



- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
	
	NSString *s = [[NSString alloc] initWithData:(NSData*) webdata .......................
	[connection release];
	theConnection =nil;
	
	[s release];

}

-(NSString *)PathForFile:(NSString *)Filename
{
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
	NSString *documentsDir = [paths objectAtIndex:0];
	NSString *FilePath = [documentsDir stringByAppendingPathComponent:Filename];
	return FilePath;
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{

	if(navigationType == UIWebViewNavigationTypeLinkClicked)
	{
		return NO;
		NSURL *url = request.URL;
		 urlString = url.absoluteString;
		[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
		NSLog(@"%@",urlString);
		return NO;
		return NO;
	}
	return YES;
}

- (void)webViewDidFinishLoad:(UIWebView *)webView 
{
	[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
	m_activity.hidden= TRUE;     
	[m_activity stopAnimating];  
	NSLog(@"Web View started loading..."); 
}


- (void)webViewDidStartLoad:(UIWebView *)webView {    
	[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
	m_activity.hidden= FALSE;    
	[m_activity startAnimating];     
	NSLog(@"Web View Did finish loading");
}


- (void)didReceiveMemoryWarning {
   
    [super didReceiveMemoryWarning];
    
}


- (void)viewDidUnload {
    [super viewDidUnload];
	self.mapView = nil;
	webVw = nil;
	m_activity = nil;
	urlString= nil;
	locationController = nil;
     
}

-(IBAction)btntoolbar_click:(id)sender
{
    [searchbar resignFirstResponder];
    if ([sender tag] == 1)
    {
        Free_RX_iCardAppDelegate *appDelegate = ......................................
        [objController release];
        appDelegate=nil;
        [appDelegate release];
        
        
    }
    else if ([sender tag] == 2) 
    {
        [self performSelectorOnMainThread:@selector(showAndHideActivityIndicator:) withObject:@"YES" waitUntilDone:NO];
        [self.locationController.locationManager startUpdatingLocation];
    }
 
}
-(void)showAndHideActivityIndicator:(NSString *)strHidden
{
	BOOL bl_hidded = NO;
	if ([strHidden isEqualToString:@"YES"])bl_hidded = YES;
	if (bl_hidded)
	{

        
		self.navigationItem.rightBarButtonItem.enabled = TRUE;
		self.navigationItem.leftBarButtonItem.enabled  = TRUE;
		[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
		[m_activity stopAnimating];
       
    
    
	}
	else 
	{
            
		self.navigationItem.rightBarButtonItem.enabled = FALSE;
		self.navigationItem.leftBarButtonItem.enabled  = FALSE;
		[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
		//[self.view bringSubviewToFront:spinnerView];
		[m_activity startAnimating];
	}
}


- (void)dealloc {
	searchbar.delegate=nil;
	[searchbar release];
	[webdata release]; webdata = nil;
    [super dealloc];
}


@end
justinwhite1 is offline   Reply With Quote
Old 09-07-2011, 07:28 PM   #10 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Quote:
@synthesize customActivityIndicator;
@synthesize locationController;
@synthesize reverseGeocoder;
@synthesize urlString;
@synthesize m_activity;
@synthesize webVw;
@synthesize mapView;
@synthesize searchbar;
BOOL isFromSearch = NO;


- (void)viewDidLoad
{
UIImageView *customActivityIndicator = [[UIImageView alloc] initWithFrame:CGRectMake(50,50,190,12)];
customActivityIndicator.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"status1.png"],[UIImage imageNamed:@"status2.png"],nil];
customActivityIndicator.animationDuration = 1.0; // in seconds
customActivityIndicator.animationRepeatCount = 0; // sets to loop
[customActivityIndicator startAnimating]; // starts animating
[self.view addSubview:customActivityIndicator];
}
Your local variable is named the same as the global property. In that case, the local variable within the method has priority so you're not really using your property. Rename the local one to something else, then assign it to the property.
baja_yu is offline   Reply With Quote
Reply

Bookmarks

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: 373
8 members and 365 guests
apatsufas, JackReidy, jeroenkeij, Sami Gh, tim0504, UMAD, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,671
Threads: 94,121
Posts: 402,904
Top Poster: BrianSlick (7,990)
Welcome to our newest member, JackReidy
Powered by vBadvanced CMPS v3.1.0

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