我有一个带有 StoryBoard (iOS 5+) 和两个 UIViewController 的项目。
任务是以编程方式实例化第二个 UIViewController (CoordinationController),但我想将它的 XIB 文件用于用户界面设计。
将 XIB 复制到 StoryBoard 的明显解决方法由于未记录的原因不起作用或不可用。 甚至规则是,如果第二个 Storyboard 的 View Controller 没有 View ,它将查找相同名称的 XIB... 不工作。
如何实例化第二个 UIViewController 并使用它的 XIB 文件?
最佳答案
您可以加载 nib 文件并在 initWithCoder: CoordinationController 方法中设置您的 View :
-(id)initWithCoder:(NSCoder *)aDecoder {
if (self = [super initWithCoder:aDecoder]) {
UINib *nib = [UINib nibWithNibName:@"CoordinationController" bundle:nil];
NSArray *nibObjects = [nib instantiateWithOwner:self options:nil];
self.view = nibObjects.lastObject;
}
return self;
}
关于ios - 如何实例化自定义 iOS UIViewController 并在 Storyboard 下使用它的 NIB?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15747351/