ios - 从 TableView 数据源中删除之前删除确认警报

标签 ios swift uitableview datasource

我试图在您从 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/

相关文章:

ios - 滚动时自定义 UITableviewCell 缓慢且滞后

ios - 如何停止以大于屏幕高度的单元格为中心的滚动

ios - 如何使用 Swift Codable 处理部分动态的 JSON?

swift - 让按钮图像贴在左侧 swift xcode

ios - UITableViewCell 无法将标签约束到右边缘

iphone - iOS 谷歌地图 SDK 价格/成本

ios - 选择行时更改 UIImageView 中的图像?

objective-c - 带有 iOS7 的 iPad 上透明背景的 UITableView/UITableViewCell 挑战

ios - 为企业自动重启 iOS 应用程序,无需越狱

swift - 如何在 Swift 中更改 TableView 单元格中 UIButton 的颜色?