简体   繁体   English

替代initWithNibName

[英]Alternative to initWithNibName

The tutorial I'm using is outdated (Before storyboards). 我正在使用的教程已过时(在情节提要之前)。 It says that initWithNibName gets called when the app loads. 它说在应用程序加载时会调用initWithNibName。 However I've read that that's no longer true. 但是我读到那不再是真的。

Also, I'm getting "Expected ';' 另外,我得到“预期的”; after top level declarator" for this, 在顶级声明者之后”

-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{


}

Which is probably an unrelated problem. 这可能是不相关的问题。

It is difficult to give a complete answer without more information. 没有更多信息,很难给出完整的答案。 You are correct in that initWithNibName is not called when using storyboards. 您是正确的,因为使用情节提要板时不会调用initWithNibName。 Most likely you can remove the initWithNibName method and ignore the code in the tutorial's initWithNibName method as most likely it just initializes a view controller using a xib file (which you probably are not using since it sounds like you set up your project to use storyboards) that was created in interface builder. 很可能您可以删除initWithNibName方法并忽略教程initWithNibName方法中的代码,因为它很可能只是使用xib文件初始化了一个视图控制器(您可能没有使用它,因为这听起来像您将项目设置为使用情节提要)在界面构建器中创建的。

Or it might be easier to follow the tutorial if you just remove storyboards from your project and do it the old way (using xib files). 或者,如果您只是从项目中删除情节提要并以旧方式(使用xib文件)进行操作,则遵循本教程可能会更容易。 That is probably what I would do. 那可能就是我会做的。

To follow up with your comment: You could place that code in viewDidLoad. 要继续您的评论:您可以将该代码放入viewDidLoad中。

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    questions=[[NSMutableArray alloc] init];
    answers=[[NSMutableArray alloc] init];
    [questions addObject:@"some question"]; 
    [answers addObject:@"answer1"];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM