我只想在 viewcontoller 的 xib 或 stroy 板上加载自定义视图(使用 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 开始多次调用。
请建议。