2013-02-22 119 views
1
  1. 推視圖控制器在我的窗口基本應用程序,我需要導航從我的appdelegate到editorview當我在我的tabbarcontroller的第二項點擊它會顯示帶有三個選項的actionsheet。無法從的appdelegate

  2. actionsheet works fine,it will show an actionheet if you choose the second item from tabbar。

  3. 但我需要推到另一種觀點認爲,當我選擇我的動作片

  4. 的第一選擇,我宣佈我的actionsheet中的appdelegate。

  5. 我已經實現actionsheetdelegate

    • (無效)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger的)buttonIndex

該方法trigerred並且它可以顯示如果我做nslog。但不能推到我想要的視圖 - 控制.. 這裏是我的代碼:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 
    { 
     if (buttonIndex == 0) 
     { 
      DetailViewController *v2 = [[DetailViewController alloc] init]; 

      NSLog(@"PUSH TRIGER"); 

      [self.window.rootViewController.navigationController pushViewController:v2 animated:YES]; 
     } 
    } 

注:我已經嵌入我tabbarcontroller和導航控制器在我的故事板

回答

2

做這樣

你爲什麼把VC分配給UITabBarController?我敢打賭UIViewController?嘗試分配UINavigationController而不是UIViewController

合成UINavigationController *navController;

self.navController = [[UINavigationController alloc] init]; 
SomeViewController *viewController = [[SomeViewController alloc] initWithNibName:@"SomeViewController" bundle:nil]; 
self.navController.viewControllers = [NSArray arrayWithObject:viewController]; 

UITabBarController *tabBarController = [[UITabBarController alloc] init]; 
[tabBarController setViewControllers:[NSArray arrayWithObjects: 
self.navController, nil]]; 

然後在您的actionsheet

[self.navController pushViewController:v2 animated:YES]; 

編輯故事板

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
    self.navController = (UINavigationController*) [storyboard instantiateViewControllerWithIdentifier:@"MyNavController"]; 

希望幫助

+0

但我已經嵌入了我的tabbarcontroller和導航在故事板,這就是爲什麼我沒有再次聲明我的tabbarcontroller – Zoro 2013-02-22 08:12:32

+0

看到我的編輯故事板 – 2013-02-22 08:18:06

+0

我認爲你是對的,也許我的故事板設計是錯誤的,我已經把segue標識符和視圖控制器標識符a nd它仍然沒有工作,你可以請檢查我的故事板,我想推到視圖控制器的紅色圓圈這裏的圖片:http://i46.tinypic.com/5jz704.png – Zoro 2013-02-22 10:23:27

-2

,而不是這個self.window.rootViewController。 navigationController

使用的UINavigationController對象

8

這是充滿了與此相關的問題不好回答的。

我希望我的礦山符合您的要求。

1 .-內部的

- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo 

// 1.-第一:實例化navigationController。通常根視圖控制器

UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController; 

// 2。 - 其次:實例化故事板 //它可能被標記爲MainStoryBoard。要小心,如果你已經改變了它

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil]; 

// 3.-第三實例的VC要導航 //在我的它被稱爲IniciarSliderViewController具體情況。不要忘記將它導入appdelegate。也要注意正確標記。在我的情況MenuSlider

IniciarSliderViewController *controller = (IniciarSliderViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"MenuSlider"]; 

//4.-而最後一個,你現在可以把你通常做的VC

[navigationController pushViewController:controller animated:YES]; 

不要猶豫,問你是否仍然有問題

+0

這幫了我很多!謝謝。 – xeravim 2014-06-27 09:19:30

+0

工程,但導航丟失 – jose920405 2015-08-03 14:19:30