如何从项目内部调用ViewController?

时间:2012-11-19 12:11:24

标签: iphone objective-c ios xcode

我的项目中有另一个项目。

enter image description here

TutorialViewController *con = [[TutorialViewController alloc] initWithNibName:@"TutorialViewController" bundle:nil WithFrame:CGRectMake(0, 0, 320, 460) AndImages:imageArray PageControlLocation:kPageControlLocationDown WithColor:[UIColor blackColor]];
    [self presentModalViewController:con animated:YES];

我想调用此TutorialViewController ViewController,但我认为(知道)编译器找不到这个nib,因为他没有在主包中找到它...

有人知道如何调用此VC吗?

1 个答案:

答案 0 :(得分:1)

您必须通过NSBundle类显式发送路径,例如:

TutorialViewController *con = [[TutorialViewController alloc] initWithNibName:@"TutorialViewController" bundle:[[NSBundle mainBundle] pathForResource:File_Name ofType:FILE_TYPE inDirectory:your_directory]] WithFrame:CGRectMake(0, 0, 320, 460) AndImages:imageArray PageControlLocation:kPageControlLocationDown WithColor:[UIColor blackColor]];
[self presentModalViewController:con animated:YES];

如果您将nil提供给bundle,那么它将在活动项目中搜索该文件。

了解更多信息:https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html