加载从故事板中实例化的nib文件 [英] loading a nib file that is instantiated from a storyboard

查看:107
本文介绍了加载从故事板中实例化的nib文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我对这个故事板概念很新。我有一个视图nibs放入故事板,每个对应一个UIViewController子类,我尝试使用以下代码加载nib文件:

So I am pretty new to this story board concept. I have a view nibs dropped in to the storyboard and each corresponding to a UIViewController subclass I have, I tried loading the nib file using the following code:

TestViewController *vc = [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:nil];
    [self.view setBackgroundColor:[UIColor blueColor]];
    [self.view setFrame:CGRectMake(0, self.profilePicture_.frameHeight + self.profilePicture_.frameY + 10, self.scrollView_.frameWidth, 100)];
    [self.view addSubview:vc.view];

然而,它给我以下错误:

However, it gives me the following error:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/aditya15417/Library/Application Support/iPhone Simulator/5.1/Applications/64E6CEC9-E6DC-4AF5-BF16-11BFB6415BDC/Pulse.app> (loaded)' with name 'TestViewController''

所以问题是,如果我有我的笔尖故事板是不是可以使用initWithNibName?如果有办法,我该怎么做?

So the question is, if I have my nib in the story board is it not possible to use the initWithNibName? If there is a way, how do I do this?

推荐答案

请使用

[self.storyboard instantiateViewControllerWithIdentifier:@"some identifier you set in IB"];

这篇关于加载从故事板中实例化的nib文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆