我试图在您从 UITable View 中删除一行之前显示一个警告。
但是,如果不将我的 View Controller 接口(interface)传递给数据源,我该如何做到这一点。
class BaseTableDataSource: NSObject, UITableViewDataSource {
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
//1. Show alert and delete the block
??? But how can you show the alert with out View controller reference??
//viewcontroller.presentViewController(alertController, animated: true, completion: nil)
}
}
}
最佳答案
通常我更喜欢创建一个 sharedInstance 通知管理器来处理我的警报,但是您可以在运行中尝试这个方法:
let alert = UIAlertController(title: "Alert", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
alert.delegate = self
alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil))
let window = UIWindow(frame: UIScreen.mainScreen().bounds)
window.rootViewController?.presentViewController(alert, animated: true,completion: nil)
更新:
根据您的代码,您还可以:
if let tableViewController = tableView.delegate {
tableViewController.presentViewController(alert, animated: true,completion: nil)
}
关于ios - 从 TableView 数据源中删除之前删除确认警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36917599/