问题
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 does my program crash when I have [buttons release]; in dealloc? Without it, it doesn't crash...
回答1:
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/
回答2:
If you have made a connection to your buttons with Interface Builder, it's your view that owns it and will release it.
回答3:
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/.
来源:https://stackoverflow.com/questions/6749563/iboutlet-collection-release-problem