Usually my code with loading custom view from xib looks like:
@implemenation MyCustomView
- (id)init
{
[self release];
if ((self = [[NSBundle loadViewFromXibName:@"MyCustomView" withClass:[MyCustomView class] owner:nil] retain]))
{
//some init here
}
return self;
}
where [NSBundle loadViewFromXibName:withClass:owner:]
- return atoreleased View, loaded from xib.
And all working properly. But when I try write under ARC equivalent code:
@implemenation MyCustomView
- (id)init
{
if ((self = [NSBundle loadViewFromXibName:@"MyCustomView" withClass:[MyCustomView class] owner:nil]))
{
//some init here
}
return self;
}
my app crash with EX_BAD_ACCESS (release message sent to deallocated instance) What happens in this case? And how can I solve this problem?
UPDATED This problem only on iOS6 SDK (iOS6 Simulator). On iOS5 SDK and iOS 5 Devices/Simulator all is fine.
UPDATED This problem appear only with table view cells, its deallocated in tableview lifecycle. I implemented static cell builder (what return cell loaded from xib) and moved internal cell initialization to awakeFromNib. Now all working properly.
I don`t understand why this problem should be - "self" is __strong and if I assign it any object it can`t be autoreleased. Is I mistaken?