简体   繁体   中英

App Shows Old XIB Instead of Storyboard

I'm updating an old iOS project that uses XIB files but want to convert to Storyboard. I created my Storyboard, connected it with the appropriate ViewControllers, removed any references that I can find to the XIB files, and set the Main Interface of the project to use my Storyboard.

However, when I run my app it still shows the XIB files instead of using the Storyboard; as if there's something still referencing them. The only one that shows the Storyboard is the initial scene/ViewController (and it's most likely because it's a newly created ViewController).

I've looked at other solutions online but to no avail. I tried:

  • Cleaning the project
  • Deleting DerivedData folder
  • Restarting Xcode and my computer
  • Updated MyApplication-info.plist
  • Removed references to ViewControllers from XIB files
  • Tried removing XIB files from project (it'll show a black screen because file is missing)

The original project target iOS 5.1, the new 6.0, and I'm using Xcode 5. Is there anything that I might be missing?


I'm not programmatically segueing to the other controllers; 我不是以编程方式选择其他控制器; I have the Storyboard take care of that. The only thing I do in the first ViewController is send a string text to the next one:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NextViewController *   nextController;

    if ([[segue identifier] isEqualToString:@"SegueToNext"])
    {
        nextController = [segue destinationViewController];
        [nextController initWithTitle:@"New"];
    }
}


This is the code for the ViewController that is showing the XIB file instead of the Storyboard. 这是显示XIB文件而不是情节提要的ViewController的代码。 As you can see, there are no calls related to loading/pushing new controllers or anything that should relate to the XIB.

#import "NextViewController.h"

@interface NextViewController ()

@end

@implementation NextViewController


-(id) initWithTitle:(NSString *) title
{
    self = [super init];
    if (self)
    {
        self.title = title;

        // Load the dictionary
        self.dictionary = [NSDictionary dictionaryWithContentsOfFile:
            [[NSBundle mainBundle] pathForResource:@"NewDictionary"
            ofType:@"plist"]];
    }

    return self;
}


-(void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    // Render new slide
    [self renderOpening];
}


-(void) viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}


-(void) renderOpening
{
    // 1st slide
    NSLog(@"renderOpening");

    // Initial settings for opening slide; all are UIOutlets (UIButton, UIImageView)
    back.hidden = YES;
    diagram.hidden = YES;
    next.hidden = NO;
    text.hidden = NO;
    avatar.hidden = NO;

    avatar.image = [[UIImage imageNamed:@"avatar"]
        rescaleImageToSize:CGSizeMake(150, 150)];

    text.text = @"Hello World";
}

@end

Within your appDelegate class file, remove any code that directs the app to launch to your old initial xib. (From within the didFinishLaunching' method) You don't need to replace it with any code to start the storyboard as this selects this from the 'Development Info' section - see below.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

Then click on your project and under the tab of 'General' within the 'Development Info' section, make sure your storyboard is selected as the main interface - see picture below.

在此处输入图片说明

Also, if you select the view controller from the storyboard that you want the app to initially start with and select it. Then go to the RHS utilities area and make sure the 'Initial Scene [ ] Is Initial View Controller bock is selected, please see picture.

在此处输入图片说明

I hope this helps,

Cheers

Jim

In the ViewController that I was segueing to, I called a custom function which returned a reference to a newly created object of the ViewController class itself:

-(id) initWithTitle:(NSString *) title
{
    self = [super init];
    if (self)
    {
        self.title = title;

        // Load the dictionary
        self.dictionary = [NSDictionary dictionaryWithContentsOfFile:
            [[NSBundle mainBundle] pathForResource:@"NewDictionary"
            ofType:@"plist"]];
    }

    return self;
}

It was left there from the old code, and I completely overlooked it. It was no longer needed now that I was using Storyboard. So instead of seeing the ViewController that I was segueing into, it was showing the old XIB file. Deleting the XIB file from the project showed an empty, black view, and removing the code [super init] showed the correct Storyboard ViewController.

Although I got it working, I'm still not certain as to why it was showing the old XIB file, even though I removed references to it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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