MaikelS
MaikelS

Reputation: 1299

Programmatically create an object then release it later

I programmatically create an ActivityIndicatorView with

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

Then when I want 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.

Upvotes: 0

Views: 243

Answers (4)

Krishnachandra Sharma
Krishnachandra Sharma

Reputation: 1342

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

Upvotes: 1

rckoenes
rckoenes

Reputation: 69469

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).

Upvotes: 2

jrturton
jrturton

Reputation: 119242

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.

Upvotes: 1

mayuur
mayuur

Reputation: 4746

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.

Upvotes: 1

Related Questions