我的應用程序由導航控制器和視圖控制器組成。我的用戶界面的某些部分是在故事板上完成的,有些是從代碼啓動的(在viewDidLoad中)。我的目標是要加載childViewController X(由一個返回按鈕,老馬欄,標籤和表)時,該應用程序從一個推送通知「正常」,通過這種方法的appDelegate推出:使用導航條正確啓動視圖
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
這可能是一個簡單的問題給你們,但我幾天之前就問過幾個問題(你可以看看我的問題歷史)。嘗試多種方法,我的應用程序後,可以:
崩潰 負荷沒有導航欄導航欄,但沒有標籤(後退按鈕不起作用) 負荷導航欄,但與黑色的屏幕下方 只有的tableView拖動 負荷到故事板上。推斷導航欄,但我有代碼,它的後退按鈕和標題。其餘全部通過.m文件中的代碼完成。
我知道人們之前曾問過這個問題,但沒有一種方法奏效。我如何通過推送通知正確加載這個childViewController?
我迄今爲止代碼:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSDictionary *dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil)
{
UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController* firstVC = [mainstoryboard instantiateViewControllerWithIdentifier:@"NotificationsViewController"];
[self.window.rootViewController addChildViewController:firstVC];
[(UINavigationController *)self.window.rootViewController pushViewController:firstVC animated:NO];
self.window.rootViewController.childViewControllers);
}}
錯誤代碼:
'-[SWRevealViewController pushViewController:animated:]: unrecognized selector sent to instance 0x14575f20'
SWRevealViewController是我對我的工具欄菜單視圖控制器庫。
我也試過這個方法:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:@"NotificationsViewController"];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = initViewController;
[self.window makeKeyAndVisible];
這將加載正確的viewController但沒有導航欄。
我剛剛嘗試過,但由於應用程序的要求,我需要該應用程序的側邊欄菜單。要使側欄菜單正常工作,必須將SWRevealViewController設置爲rootViewController。 – user3178926
那麼UINavigationController在哪裏?您必須調用pushViewController:animated:on something .... – devdavid
我處理過類似設置的一種方法是讓我的自定義ViewController成爲rootViewController,並在IB中將ContainerView放入其中,然後將其設置爲嵌入segue嵌入一個NavigationController。在prepareForSegue上,我檢查它是否爲嵌入式segue,然後將navigationViewer的引用保存爲navigationController,並將其自己設置爲委託,以便知道何時推入並彈出所有其他控制器。 – devdavid