0

update 1

Attributes inspector

update 1

update 0

Execution aborts when I implement the code suggested in the answer provided.

update 0

This fine question and answer does not quite deal with my Universal app which had both a iPhone and iPad xibs and now wants to use a storyboard.

This is the xib based BSAppDelegate.m (before storyboard)

    #import "BSAppDelegate.h"
    #import "BSViewController.h"

    @implementation BSAppDelegate

    NSString *receivedData;

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // Override point for customization after application launch.
        // return YES;
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            self.viewController = [[BSViewController alloc] initWithNibName:@"BSViewController_iPhone" bundle:nil];
        } else {        
            self.viewController = [[BSViewController alloc] initWithNibName:@"BSViewController_iPad" bundle:nil];
    }
        self.window.rootViewController = self.viewController;   
        [self.window makeKeyAndVisible];
        return YES;
    }

I have tried to insert the following code right after the else above but I cannot quite complete the code fix which needs to set self.viewController to be compatible with the above code.

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"BSViewController"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];

Can you show me how to fix my code, please? I am using Xcode 4.5.2 and developing for iOS 6.

Community
  • 1
  • 1
zerowords
  • 2,915
  • 4
  • 29
  • 44

1 Answers1

0

two issues:

  1. just set self.ViewController to your vc which you get from the storyboard :)

        #import "BSAppDelegate.h"
    #import "BSViewController.h"
    
    @implementation BSAppDelegate
    
    NSString *receivedData;
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // Override point for customization after application launch.
        // return YES;
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            self.viewController = [[BSViewController alloc] initWithNibName:@"BSViewController_iPhone" bundle:nil];
        } else {        
            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil];
            UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"BSViewController"];
            vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
            self.viewController = (id)vc;
        }
        self.window.rootViewController = self.viewController;   
        [self.window makeKeyAndVisible];
        return YES;
    }   
    
  2. in your storyboard, you have no identifier named 'BSViewController' set so the call instantiateViewControllerWithIdentifier will fail. set the identifier (aka the Storyboard ID) visible in your screenshot

Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
  • Updated my question with a image showing the termination message. Please take a look. Your answer looks right, so maybe I have not followed your answer correctly. – zerowords Feb 17 '13 at 16:29
  • well the error states the storyboard doesn't contain a BSViewController. .... but you try to reference it in your question -- the storyboard seems wrong – Daij-Djan Feb 17 '13 at 16:31
  • you have to set tge identifier on the VC you want to reference! (in IB) – Daij-Djan Feb 17 '13 at 16:32
  • id say, click on the first VC (in your image) go to the inspector open the third tab (on the right) and fill out the identifier textbox with 'BSViewController' – Daij-Djan Feb 17 '13 at 16:34
  • My image is showing the open third tab (Identity inspector) filled out as you say, isn't it? I am going to add another image from the (fourth) Attributes inspector in case that tells something. – zerowords Feb 17 '13 at 16:53
  • 1
    ah sorry its the storyboard id you have to set thats whats the identifier is called today – Daij-Djan Feb 17 '13 at 17:04
  • Can you be more specific? I don't know where to set that, other than naming the file `MainStoryboard_iPad.storyboard`. – zerowords Feb 17 '13 at 17:07
  • I added this comment before your last, but it does not show. I thought I had tried before to change the "Identifier" in this line `UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"MainStoryboard_iPad"];`, but now it works fine. Anyhow, thanks. That seems to be working. Next I need to post another question about how to handle an `OverlayViewController` which was done as its own nib before, but now I have its overlaid view controller in the storyboard. Stay tuned. – zerowords Feb 17 '13 at 18:10