ios - 使用 UIAlertController 按钮将自定义单元格添加到 tableView

标签 ios swift uitableview uialertcontroller

我创建了一个 UITableView 并创建了一些单元格并为它们指定了标识符。我还创建了一个 UIAlertController 来在同一个 View Controller 上按下按钮时显示弹出窗口。我希望能够根据用户在警报弹出窗口中点击的按钮,使用适当的单元格将新行插入到表中。 帮助?

最佳答案

你可以这样试试

    let alert = UIAlertController(title:"Test", message: "Message", preferredStyle: UIAlertControllerStyle.alert)
    alert.addAction(UIAlertAction(title: "Add Row", style: UIAlertActionStyle.default, handler: { (action) -> Void in
        tblView.insertRows(at: [IndexPath], with: UITableViewRowAnimation.left)
        And update your data Sourse 
    }))
    alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil))
    self.presentViewController(alert, animated: true, completion: nil)

希望对你有帮助

关于ios - 使用 UIAlertController 按钮将自定义单元格添加到 tableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40908176/

相关文章:

ios - 如何扩展 RealmOptional 以在 Swift 中的 Float 上添加一个函数?

ios - Swift - 函数 viewWillAppear

objective-c - HDFC iOS SDK 崩溃以集成到 Swift 中?

ios - 将语言从(英语)更改为阿拉伯语时,如何从左到右更改 SWReaveal 侧边菜单形式

swift - 迁移到 Swift 3 - 在 URL session 期间出现以下错误

ios - 网站未在 UIWebView 中加载

iOS - UITableView 的 UIRefreshControl 与 UITableViewController 的 UIRefreshControl

swift - Xcode 从另一个 viewController 传递的变量设置标签的文本会导致崩溃

ios - 自动布局 - 可折叠 View (垂直)

ios - WKWebView iOS 13 中的 DeviceMotion 和 DeviceOrientation