簡體   English   中英

任何視圖控制器可見時,AppDelegate中的performSegueWithIdentifier

[英]performSegueWithIdentifier in AppDelegate when any view controller is visible

當應用程序收到本地通知時,我的AppDelegate中就有此方法。 我希望它在收到通知時對視圖控制器執行排序。 當當前可見的視圖控制器是根視圖控制器時,此方法工作正常,但是當它是任何其他視圖控制器時,它將不起作用。 而且由於我未使用導航控制器,所以無法訪問visibleViewController 我怎樣才能解決這個問題?

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
    NSString *segueId = @"segueToTrigger";
    [self.window.rootViewController performSegueWithIdentifier:segueId sender:self];
}

在情節提要中,為視圖控制器提供一個storyboard_id。 采用

    UIViewController * vc = [self.storyboard instantiateViewControllerWithIdentifier:@"[<your_story_board_id>]"];
    [[[[UIApplication sharedApplication]delegate]window]addSubview:vc.view];

切記為vc分配一個強屬性,否則它將從函數中釋放出來。

暫無
暫無

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

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