xcode界面构建器:放置在其他笔尖内时不显示nib

时间:2014-05-08 11:56:55

标签: ios xcode uiview interface-builder nib

enter image description here我已经开发了一个带有custom UIView文件的nib,以便我可以在需要时重复使用它。现在问题是我有一个nib UIViewController并且我在其中拖放虚拟UIView并将Class Name更改为自定义视图的类名。这在运行我的应用程序时工作正常。我可以在运行时在屏幕上看到自定义视图。但我在Interface builder中看不到它。所以,我的问题是,是否可以通过界面构建​​器在视图控制器的nib中看到自定义视图的布局?

1 个答案:

答案 0 :(得分:0)

您无法从另一个笔尖内加载笔尖。

您可以将视图控制器的视图中的视图作为占位符,然后在viewDidLoad中加载自定义视图的笔尖来解决此问题:

- (void)viewDidLoad {
    [super viewDidLoad];
    UINib *customViewNib = [UINib nibWithNibName:@"CustomView" bundle:nil];
    CustomView *customView = [[customViewNib instantiateWithOwner:self options:nil] objectAtIndex:0]

    customView.frame = self.placeholderView.bounds;
    [self.placeholderView addSubView:customView];
}
相关问题