开发者

IBOutlet collection release problem

I have an array for IBOutlet collection

.h

@interface UpisiRezultat : UIViewController {
    NSArray *buttons;
}

@property (nonatomic, retain) IBOutletCollection(UIButton) NSArray *buttons;

.m

@synthesize buttons;

- (void)viewDidLoad
{
    [self setValue:[UIFont fontWithName:@"NeverSayNever" size:22] forKeyPath:@"buttons.font"];
    [super viewDidLoad];
}

- (void)viewDidUnload
{
    buttons = nil;
}

- (void)dealloc
{
    [buttons release]; --> Error
    [super dealloc];
}

Why do开发者_JS百科es my program crash when I have [buttons release]; in dealloc? Without it, it doesn't crash...


updated(Dec1) code and Tested.

- (void)dealloc {

    self.buttons = nil;

    [super dealloc];
}

you should not release them.

http://www.bobmccune.com/2011/01/31/using-ios-4s-iboutletcollection/


If you have made a connection to your buttons with Interface Builder, it's your view that owns it and will release it.


Since buttons is an NSArray and it is explicitly retained, then it must be released and then set to nil in -dealloc.

See Darren's answer at: Settings IBOutlets to nil in dealloc See an IBOutletCollection example at: http://www.bobmccune.com/2011/01/31/using-ios-4s-iboutletcollection/.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜