My question regards the use of activity indicator in an iPhone project.
I have a class that contains an UIActivityIndicatorView
@interface StatusView : UIView
{
UIActivityIndicatorView *indicator;
UILabel *textLabel;
}
- (id)initWithFrame:(CGRect)frame Text:(NSString*)text andShowIndicator:(BOOL)value;
In my business logic code I call [indicator startAnimating] and the frame appears at the bottom of the screen. The code also contains a dealloc method that releases the indicator
- (void)dealloc
{
[indicator release];
[super dealloc];
}
Most of the time the indicator works well, however there are a few occasions that never disappears.
Do I always need to explicitly call the stopAnimating method? Does the release handle it?
What is the proper usage?
stopAnimating:
method stops the wheel of UIActivityIndicatorView
and release
release the object.
In Objective-C each object has an internal counter that is used to keep track of all references used by the objects or object has. [object retain]
increments the counter by 1 and [object release]
decrements the counter by 1. When counter reaches to zero, dealloc is then called. release
is about memory management while stopAnimating:
is a functionality of UIActivityIndicatorView
.
So if you want to stop animating your UIActivityIndicatorView
you would have to call stopAnimating:
method. In ARC dont have to do release
so better to use ARC
.
the best way when you are using this object is stopAnimating when you want to stop, remove from super view ( [activityObject removeFromsuperview] ) and finally release it. [ activityObject release];