【发布时间】:2020-03-06 10:53:46
【问题描述】:
我正在通过表格视图中的尾随滑动创建警报。 单击编辑时,我正在尝试实例化另一个视图控制器并将其显示为弹出窗口。
问题是弹出窗口要么显示在同一屏幕上,要么显示为弹出窗口时缺少导航栏。
我在 stackoverflow 上查看了不同的线程,但找不到解决方案。
在不同的屏幕上,当我将视图控制器设置为从情节提要中显示为弹出窗口时,这非常有效,但我不知道如何从警报内部让它工作。
我添加了不起作用的代码的核心部分。很高兴添加您需要查看的任何其他详细信息。
到目前为止我尝试了什么:
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, animated: 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")
})
【问题讨论】: