加載/創建新視圖窗體xib文件時出現問題。我得到EXEC_BAD_ACCESS代碼= 2,在我的調用堆棧上,我看到多次調用initWithCoder方法。我不明白爲什麼會發生這種情況,因爲我只爲我的類調用alloc init一次。 下面我的代碼:在initWithCoder中獲取EXEC_BAD_ACCESS
@interface SongListView : NSView
@property (nonatomic, strong) IBOutlet NSScrollView* view;
@end
@implementation SongListView
- (id)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if(self)
{
[self setup];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder: aDecoder];
if(self)
{
[self setup];
}
return self;
}
- (void)setup
{
NSArray *nib;
[[NSBundle mainBundle] loadNibNamed:@"scrollTabViewItemWithTableView"
owner:self
topLevelObjects:&nib];
[self addSubview: self.view];
}
@end
,這是我創建SongListView:
SongListView* tableView = [[SongListView alloc] init];
有人可以解釋我發生了什麼,爲什麼我得到多發呼叫的initWithCoder方法,以及如何解決它?
本身,'-init'很好,因爲它與CGREctZero相當於'initWithFrame:'。不過,接下來會發生一些混亂。 – coverback