【问题标题】:Controller being pushed twice on iPad screen控制器在 iPad 屏幕上被按下两次
【发布时间】:2017-11-03 12:30:26
【问题描述】:

我正在尝试通过单击操作表上显示的选项之一来切换到另一个控制器。它在 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 触发动作时没有显示,但新控制器堆叠在顶部。FirstController, SecondController 在上一个屏幕单击 getRecipe/Login 按钮后。

【问题讨论】:

    标签: ios swift ipad navigation segue


    【解决方案1】:

    您可以尝试从另一个操作执行转场

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

    【讨论】:

    • 我需要把这个放在动作调用中吗?
    • 是的和以前一样的位置
    • { OperationQueue.main.addOperation 中的操作 { self.performSegue(withIdentifier: "GetRecipeID", sender: nil) }} 不幸的是,这并没有改变任何东西。
    猜你喜欢
    • 1970-01-01
    • 2011-01-26
    • 2016-03-09
    • 1970-01-01
    • 2011-03-31
    • 1970-01-01
    • 2011-08-10
    • 1970-01-01
    相关资源
    最近更新 更多