Ios5 计算用于UIViewController的NSBundle

Ios5 计算用于UIViewController的NSBundle,ios5,nsbundle,Ios5,Nsbundle,当使用-(id)initWithNibName:bundle:实例化UIViewController时,您可以传入一个bundle 有没有办法让实例化的视图控制器找出它的原始捆绑包是什么 我有一个容器UIViewController,我想使用创建父对象时使用的相同捆绑包实例化它的子UIViewController。除了将捆绑包保存为ivar之外,还有其他方法可以获得此信息吗 ContainerViewController *pvc = [[ContainerViewController allo

当使用
-(id)initWithNibName:bundle:
实例化UIViewController时,您可以传入一个bundle

有没有办法让实例化的视图控制器找出它的原始捆绑包是什么

我有一个容器UIViewController,我想使用创建父对象时使用的相同捆绑包实例化它的子UIViewController。除了将捆绑包保存为ivar之外,还有其他方法可以获得此信息吗

ContainerViewController *pvc = [[ContainerViewController alloc] 
initWithNibName:nil bundle:[NSBundle mainBundle]];

// inside ContainerViewController:
ChildViewController *cvc = [[ChildViewController alloc] 
initWithNibName:nil bundle:parentBundle];

UIViewController
有一个名为
nibBundle
的属性,其中包含您要查找的内容:

nibBundle
返回接收器的nib包(如果存在)的名称。 (只读)

@属性(非原子、只读、保留)NSBundle*nibBundle

可用性
iOS 2.0及更高版本提供。
另请参见
-initWithNibName:bundle:

@property nibName


UIViewController.h

因此,您可以使用:

ChildViewController *cvc = [[ChildViewController alloc] initWithNibName:nil bundle:self.nibBundle];

谢谢-我不知怎么错过了UIViewController类上的nibBundle属性。