2012-10-02 8 views
27

जैसे ही ऐप आईपैड और आईफोन के लिए अलग-अलग स्टोरीबोर्ड का उपयोग करता है, मैं चाहता हूं कि मेरा ऐप आईफोन 5 के लिए एक अलग स्टोरीबोर्ड का उपयोग करे। चूंकि आईफोन 5 के लिए डिफ़ॉल्ट स्टोरीबोर्ड का चयन करने के लिए Info.plist में कोई विकल्प नहीं है, तो मैं कैसे प्रोग्रामेटिक रूप से स्टोरीबोर्ड पर कॉल करें?आईफोन 5 के लिए अलग स्टोरीबोर्ड पर कैसे स्विच करें?

मैं इस ऐप के लिए ऑटोलाउट का उपयोग नहीं करना चाहता, जब तक यह बिल्कुल अंतिम उपाय न हो। मैं समझता हूं कि कोई उपयोगकर्ता एक आईफोन 5 या अन्य डिवाइस को उसी स्क्रीन आकार के साथ उपयोग कर रहा है या नहीं। मुझे सिर्फ यह जानने की जरूरत है कि प्लिस्ट के बिना डिफ़ॉल्ट स्टोरीबोर्ड कैसे सेट करें।

उत्तर

55

मैं सप्ताह के एक ही जवाब जोड़ी के लिए देख रहा था पहले यहां मेरे समाधान आशा में मदद करता है है ..

-(void)initializeStoryBoardBasedOnScreenSize { 

    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) 
{ // The iOS device = iPhone or iPod Touch 


    CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size; 

    if (iOSDeviceScreenSize.height == 480) 
    { // iPhone 3GS, 4, and 4S and iPod Touch 3rd and 4th generation: 3.5 inch screen (diagonally measured) 

     // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone35 
     UIStoryboard *iPhone35Storyboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone35" bundle:nil]; 

     // Instantiate the initial view controller object from the storyboard 
     UIViewController *initialViewController = [iPhone35Storyboard instantiateInitialViewController]; 

     // Instantiate a UIWindow object and initialize it with the screen size of the iOS device 
     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

     // Set the initial view controller to be the root view controller of the window object 
     self.window.rootViewController = initialViewController; 

     // Set the window object to be the key window and show it 
     [self.window makeKeyAndVisible]; 
    } 

    if (iOSDeviceScreenSize.height == 568) 
    { // iPhone 5 and iPod Touch 5th generation: 4 inch screen (diagonally measured) 

     // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4 
     UIStoryboard *iPhone4Storyboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone4" bundle:nil]; 

     // Instantiate the initial view controller object from the storyboard 
     UIViewController *initialViewController = [iPhone4Storyboard instantiateInitialViewController]; 

     // Instantiate a UIWindow object and initialize it with the screen size of the iOS device 
     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

     // Set the initial view controller to be the root view controller of the window object 
     self.window.rootViewController = initialViewController; 

     // Set the window object to be the key window and show it 
     [self.window makeKeyAndVisible]; 
    } 

    } else if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) 

    { // The iOS device = iPad 

    UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController; 
    UINavigationController *navigationController = [splitViewController.viewControllers lastObject]; 
    splitViewController.delegate = (id)navigationController.topViewController; 

    } 
} 

कॉल AppDelegate ddiFinishLaunchingWithOptions के तहत इस विधि: विधि और यह भी ठीक से नाम अपने स्टोरीबोर्ड मत भूलना

आशा में मदद करता है ...

+0

धन्यवाद! मैंने इस सटीक उत्तर की तलाश में बहुत अधिक समय बिताया है। समस्या हल हो गई! – user1486548

+1

मुझे खुशी है कि यह काम करता है ... – lionserdar

+0

विधि ठीक से संकलित करती है, लेकिन ऐसा लगता है कि वास्तव में मेरे अंत में कुछ भी नहीं लगता है। कोई विचार? – Klinetel

4

यह मेरे लिए काम किया - एक समारोह में स्टोरीबोर्ड हो रही रैपिंग के साथ मामूली शोधन

-(UIStoryboard*) getStoryboard { 
    UIStoryboard *storyBoard = nil; 
    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {   
     storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil]; 
    }else{ 
     if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone){ 
      // The iOS device = iPhone or iPod Touch 
      CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size; 
      if (iOSDeviceScreenSize.height == 480){ 
       // iPhone 3/4x 
       storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone_4" bundle:nil]; 

      }else if (iOSDeviceScreenSize.height == 568){ 
       // iPhone 5 etc 
       storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone_5" bundle:nil]; 
      } 
     } 
    } 

    ASSERT(storyBoard); 
    return storyBoard; 
} 

UIStoryboard* mainStoryBoard = [self getStoryboard]; 
    self.initialViewController = [mainStoryBoard instantiateInitialViewController]; 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    self.window.rootViewController = self.initialViewController; 
    [self.window makeKeyAndVisible]; 
+0

क्यों एएसएसईआरटी (स्टोरीबोर्ड)? –

+0

सिर्फ एक सैनिटी जांच है कि स्टोरीबोर्ड मौजूद है। एएसएसईआरटी मैक्रो रिलीज बिल्ड – gheese

+0

आह में कोई ऑप नहीं होना चाहिए ... मैंने कभी इसका उपयोग नहीं किया है, इसलिए यह सुनिश्चित नहीं था। मुझे अब संदर्भ मिल गया है ... इनका उपयोग करने पर कोई अनुशंसित ट्यूटोरियल? –

संबंधित मुद्दे