开发者

Programmatically create an object then release it later

I programmatically create an ActivityIndicatorView with

UIActivityIndicatorView* cactivity = [[[UIActivityIndicatorView alloc] 
 initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] retain];

Then when I w开发者_如何学JAVAant to stopAnimating and release in the next

- (void)connectionDidFinishLoading, im using an undeclared identifier? But i thought i retained it and had to release it myself.


First off there is no need to retain the UIActivityIndicatorView after you alloc init it, it already has an retain count of 1.

Just declare an UIActivityIndicatorView in the .h file, so you can then reference it as a Instance variable. (thnx Rob).


Local Declaration : You have declared the UIActivityIndicator in a local method due to which it is unreachable to other methods. You'll have to declare in the header file. Also, give it property of retain. Then, you can access it wherever you want.

No need of Retain Message : Also, when you have initialized it, its retain count is increased by 1, so no need to pass the retain message to it. You'll be having access to it anyways.


Undeclared identifier means the variable is not defined in the current scope. To have the same variable available in multiple methods, make it a class ivar or property.


Try to get to the result or avoid warnings using "autorelease". But this is not suppose to be good in every case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜