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?
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];
stopAnimating:
method stops the wheel ofUIActivityIndicatorView
andrelease
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 whilestopAnimating:
is a functionality ofUIActivityIndicatorView
. So if you want to stop animating yourUIActivityIndicatorView
you would have to callstopAnimating:
method. In ARC dont have to dorelease
so better to useARC
.