在呈现的视图控制器上的 UITableViewCell 中呈现 UIAlertController [英] Present UIAlertController in UITableViewCell on Presented View Controller
问题描述
我想显示 UITableViewCell
类中的 UIAlertController
.
I want to show UIAlertController
from UITableViewCell
class.
在搜索时我发现 UIApplication.shared.keyWindow?.rootViewController?.present
这样做会显示它.
While searching I found that UIApplication.shared.keyWindow?.rootViewController?.present
doing this will display it.
如果打开的 ViewController
位于 NavigationController
下,这将起作用,因为我的 rootViewController
是 NavigationController
和显示 cell
的视图.
Which works in the case if the opened ViewController
is under NavigationController
because my rootViewController
is a NavigationController
and the view under which the cell
is being presented.
那么我如何在 UITableViewCell
中呈现 UIAlertController
呈现出来.
So how can I present UIAlertController
in UITableViewCell
which is presented.
推荐答案
您需要实现 delegate
模式.
创建一个由你的控制器实现的protocol
,并将一个weak
引用从这个控制器分配给你的单元.
Create a protocol
implemented by your controller and assign a weak
reference from this controller to your cell.
然后使用类似 cell.delegate.didPerformAction()
单元格是一个View
,它不应该负责呈现任何东西.
The cell is a View
, and it should not be responsible for presenting anything.
这篇关于在呈现的视图控制器上的 UITableViewCell 中呈现 UIAlertController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!