UIActivityIndicatorView proper usage

懵懂的女人 提交于 2019-12-11 04:42:11

问题


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?


回答1:


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.




回答2:


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];



来源:https://stackoverflow.com/questions/12622301/uiactivityindicatorview-proper-usage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!