控制器在iPad屏幕上被按两次

时间:2017-11-03 12:30:26

标签: ios swift ipad navigation segue

我试图通过单击操作表上显示的选项之一来切换到另一个控制器。它在iPhone屏幕上运行得很好,并且它被推送到适当的场景,但在iPad上出现问题。我一直在寻找类似的问题,但没有成功。

@IBAction func actionSheet(_ sender: UIButton) {

    let alert = UIAlertController(title: "Please select one of the options", message: nil, preferredStyle: .actionSheet)

    let cancelActionButton = UIAlertAction(title: "Cancel", style: .cancel) { action -> Void in }

    let recipeActionButton = UIAlertAction(title: "Get The Recipe", style: .default) { action in self.performSegue(withIdentifier: "GetRecipeID", sender: self) }

    let facebookActionButton = UIAlertAction(title: "Login with Facebook", style: .default) { action in self.handleCustomFacebookLogin() }

    //actions
    alert.addAction(cancelActionButton)
    alert.addAction(recipeActionButton)
    alert.addAction(facebookActionButton)

    // support ipad
    if let popoverController = alert.popoverPresentationController {
        popoverController.sourceView = sender
        popoverController.sourceRect = sender.bounds
    }
    self.present(alert, animated: true, completion: nil)
}

此方法也无效:

  let viewController = UIStoryboard(name: "Detail", bundle: nil).instantiateViewController(withIdentifier: "DetailsVC") as! DetailsViewController
  let recipeActionButton = UIAlertAction(title: "Get The Recipe", style: .default, handler: { action in
  self.navigationController?.pushViewController(viewcontroller, animated: true)})

从iPhone推送时,我在控制台中收到此警告:

pushViewController:animated: called on <UINavigationController 
0x7fd96a81f800> while an existing transition or presentation is 
occurring; the navigation stack will not be updated.

当我从iPad触发操作时未显示,但新控制器位于顶部。FirstControllerSecondController  点击上一屏幕的getRecipe / Login按钮后。

1 个答案:

答案 0 :(得分:0)

你可以尝试从另一个操作中执行segue

OperationQueue.main.addOperation {   
    self.performSegue(withIdentifier: "GetRecipeID", sender: nil)
}