2016-12-02 38 views
1

我使用自定義URL方案打開我的應用程序。 我的代碼如下用於從tabbar打開視圖。但是,我應該如何打開一個特定的視圖。如何從appdelegate打開視圖?

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { 

if ([url.host isEqual: @"main"]) 
{ 
    UITabBarController *tab = (UITabBarController *)self.window.rootViewController; 
    tab.selectedIndex = 0; 
} 
+0

您使用的故事板? –

+0

@jigneshVadadoriya是 – hatched

回答

0

你需要檢查URL方案如下:

if ([[url scheme] isEqualToString:@"main"]) { 
     UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
     UITabBarController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"tabBarcontroller"]; // if you are use storyboard . 
     [self.Window setRootViewController:rootViewController]; 
    } 
+0

如何設置故事板名稱和標識符? – hatched

+0

你可以設置tabbar的storyboard id如下:http://stackoverflow.com/a/11604827/3901620 – KKRocks

+0

和故事板名稱就是你的故事板文件名。例如。 Main.storyboard – KKRocks

0
if ([[url scheme] isEqualToString:@"main"]) { 
     UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
     UITabBarController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"tabBarcontroller"]; // if you are use storyboard . 
    tab.selectedIndex = 0; 
     [self.Window setRootViewController:rootViewController]; 
    }