无法从代码中的Alert内部弹出窗口

我正在通过在表视图中尾随滑动来创建警报。 在单击“编辑”时,我试图实例化另一个视图控制器并将其显示为弹出窗口。

问题是弹出窗口要么显示在同一屏幕上,要么显示为弹出窗口缺少导航栏。

我在stackoverflow上研究了不同的线程,但是找不到解决方案。

在另一个屏幕上,当我将视图控制器设置为从情节提要中显示为弹出窗口时,这种方法非常有效,但我不知道如何从Alert内部使用它。

我添加了无效的代码的核心部分。很高兴添加您需要查看的其他详细信息。

到目前为止我尝试过的事情:

1)为vc设置演示样式

vc.modalPresentationStyle = .popover

2)尝试进行过渡-这将在同一窗口中显示vc

            let transition = CATransition()
            transition.duration = 0.5
            transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
            transition.type = CATransitionType.reveal
            transition.subtype = CATransitionSubtype.fromTop
            self.navigationController?.view.layer.add(transition,forKey: nil)
            self.navigationController?.pushViewController(vc,animated: false)

3)结果与#2相同

self.navigationController?.present(vc,动画:false)

4)Self.Present,不带导航控制器。

let modifyaction = UIContextualaction(style: .normal,title:  "Manage",handler: { (ac:UIContextualaction,view:UIView,success:(Bool) -> Void) in
            print("Update action ...")


            let alert = UIAlertController()

            alert.addaction(UIAlertaction(title: "Edit",style: .default,handler:{ (UIAlertaction)in
                    print("User click Edit button")

                let vc = self.storyboard?.instantiateViewController(withIdentifier: "ManageCategoryViewController") as! ManageCategoryViewController

                vc.selectedIdx = indexPath.row
                vc.categoryListArray = self.categoryListArray
                vc.type = "update"
                //vc.modalPresentationStyle = .popover

                /*
                let transition = CATransition()
                transition.duration = 0.5
                transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
                transition.type = CATransitionType.reveal
                transition.subtype = CATransitionSubtype.fromTop
                self.navigationController?.view.layer.add(transition,forKey: nil)
                self.navigationController?.pushViewController(vc,animated: false)
                */

                self.navigationController?.present(vc,animated: false)

            }))

alert.addaction(UIAlertaction(title: "Cancel",style: .cancel,handler:{ (UIAlertaction)in
                print("User click Cancel button")
            }))

            self.present(alert,animated: true,completion: {
                print("completion block")
            })
wangshuaiws0 回答:无法从代码中的Alert内部弹出窗口

在进一步阅读并尝试多个选项时,我之所以能够解决此问题,并不是由于从警报内部启动了弹出窗口。

https://developer.apple.com/documentation/uikit/windows_and_screens/displaying_transient_content_in_a_popover

如果您需要导航控制器,则可以按照以下帖子中的答案之一的建议添加导航控制器。

presentViewController and displaying navigation bar

发布代码以防他人使用。

let navController = UINavigationController(rootViewController: vc)
                vc.modalPresentationStyle = .popover
                self.navigationController?.present(navController,animated: true) {
                     // The popover is visible.
                }
本文链接:https://www.f2er.com/3128820.html

大家都在问