簡體   English   中英

無法從Appdelegate推送ViewController

[英]Cannot push viewcontroller from appdelegate

  1. 在我的窗口基礎應用程序中,當我單擊我的tabbarcontroller的第二項時,需要從我的appdelegate導航到editorview,它將顯示一個帶有三個選項的動作表。

  2. 動作表工作正常,如果您從標簽欄中選擇第二項,它將顯示一個動作表。

  3. 但是,當我選擇操作表中的第一個選項時,我需要推送到其他視圖

  4. 我在appdelegate中聲明我的操作表。

  5. 我已經實現了actionsheetdelegate

    • (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

該方法被觸發,它可以顯示我是否執行nslog。 但是它不能推送到我想要的ViewController。這是我的代碼:

- (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和導航控制器

充滿了與此問題相關的錯誤答案。

希望我的符合您的要求。

1.-內部

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

// 1 .--首先:實例化navigationController。 通常是rootviewcontroller

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

// 2.-第二:實例化Storyboard //它可能被標記為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];

不要猶豫,問您還有問題嗎

像這樣

您為UITabBarController分配了什么VC? 我打賭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]];

然后在您的操作表上

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

編輯情節提要

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

希望能有所幫助

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

使用UINavigationController對象

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM