0
我只想在viewcontoller的xib或stroy board上加載自定義視圖(使用xib)。最佳做法也是這樣做。如何使用xib或故事板上的xib加載自定義視圖
我已經在下面使用了awakeAfterUsingCoder函數代碼。
(id) awakeAfterUsingCoder:(NSCoder*)aDecoder
{
BOOL theThingThatGotLoadedWasJustAPlaceholder = ([[self subviews] count] == 0);
if (theThingThatGotLoadedWasJustAPlaceholder)
{
CustomView* theRealThing = (id) [CustomView view];
theRealThing.frame = self.frame;
theRealThing.autoresizingMask = self.autoresizingMask;
return theRealThing;
}
return self;
}
但使用此功能後,我的awakeFromNib開始多次調用。
請注意。