swift - 弹出窗口在代码中的警报内部不起作用
问题描述
我正在从表格视图中的尾随滑动创建警报。单击编辑时,我试图实例化另一个视图控制器并将其显示为弹出窗口。
问题是弹出窗口要么显示在同一屏幕中,要么显示为弹出窗口时缺少导航栏。
我查看了 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, 动画: 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")
})
解决方案
在进一步阅读并尝试多个选项时,我能够解决此问题不是因为弹出窗口是从警报内部启动的。
如果您需要导航控制器,您可以按照以下帖子中的答案之一的建议添加导航控制器。
发布代码以防它对某人有用。
let navController = UINavigationController(rootViewController: vc)
vc.modalPresentationStyle = .popover
self.navigationController?.present(navController, animated: true) {
// The popover is visible.
}
推荐阅读
- presto - 如何将一个ID对应的多行变成单行 - Presto
- c# - 使用 OBDC Topspeed 驱动程序或 Topscan 从 .TPS 数据库中批量删除记录
- python - Pyspark - 使用函数添加具有值的新列 - 分组依据和最大值
- python - 如何解决 Scrapy 和 Selenium Uncaught ReferenceError?
- reactjs - 在 UI 管理器中找不到“RNCWebView”
- apache-spark - 如何仅选择至少一个值与前一行发生更改的行
- mysql - mysql 选择出现在与订单数量一样多的行中的产品
- python - 如何在相关矩阵中找到高值?
- dictionary - 如何在 Hive 的复杂列中选择有限数量的值?
- reactjs - 将使用 json-server 作为后端的 create-react-app 部署到 Godaddy cPanel