PDA

View Full Version : background image for UIButton




jagatnibas
Nov 15, 2009, 01:05 PM
i am doing something like below


UIImage *img = [UIImage imageNamed:@"a.png"];
UIButton *btn =[[valid instance from nib file]]

[btn setbackgroundImage:img forState:UIControlStateNormal];
[img release];


shouldnot i be able to release img ?
because i dont need the image anymore i ca release img, isn;t it ?

in UIImageView we are able to do that, in button why not ?

like in

UIImageView = alloc
setImage:img
add subview: imgview
[img release];
[imgview release];

it just works fine !

regards
jagat



robbieduncan
Nov 15, 2009, 01:10 PM
Go and read the memory management guide: you should not release img as you do not create it with an alloc/init or copy constructor so it is autoreleased.

sneha
Nov 16, 2009, 02:41 AM
Normally it releases the image object.:rolleyes:

robbieduncan
Nov 16, 2009, 03:20 AM
Normally it releases the image object.:rolleyes:

Normally what releases the object? That makes no sense.

sneha
Nov 16, 2009, 08:09 AM
Normally what releases the object? That makes no sense.

If we do


UIImage *img = [UIImage imageNamed:@"1.png"];
[img release];


Because after assigning it you dont need the object of UIImage.

If you are more interested in memory management (UIImage) please go through this link i hope it helps because it helped me a lot. :)

http://www.alexcurylo.com/blog/2009/01/13/imagenamed-is-evil/

:)