【问题标题】:Using UIAlertController buttons to add custom cells to a tableView使用 UIAlertController 按钮将自定义单元格添加到 tableView
【发布时间】:2016-12-01 10:27:34
【问题描述】:

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

【问题讨论】:

  • 当您从UIAlertController“注册新的单元格内容”时,将其添加到您的数组/字典或任何用作您的UITableView 数据源中。并致电yourTableView.reloadData()

标签: ios swift uitableview uialertcontroller


【解决方案1】:

你可以这样试试

    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)

希望对你有帮助

【讨论】:

    【解决方案2】:

    您可以根据部分进行更改。

    self.tblView.beginUpdates()
    self.tblView.insertRows(at: [IndexPath.init(row: self.yourArray.count-1, section: 0)], with: .automatic)
    self.tblView.endUpdates()
    

    【讨论】:

      猜你喜欢
      • 2017-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-10
      • 1970-01-01
      • 2013-05-10
      • 2020-10-20
      相关资源
      最近更新 更多