作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望能够删除 tableView
中的行/项目。tableView
填充有 struct
结构:
struct Items {
var name: String = ""
var count = Int()
}
var itemsInStore : [Items] = []
tableView
的填充如下:
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "CheckOutCell") as! CheckOutTableViewCell
let name = itemsInStore[indexPath.row].name
let count = itemsInStore[indexPath.row].count
cell.checkOutLabel.text = "\(count) Pcs \(name)"
cell.delegate = self
return cell
}
按钮:
我一直在尝试不同的版本,但还没有成功:
extension CheckOutViewController: RemoveItemDelegate
{
func didDeleteItemCell(cell: CheckOutTableViewCell) {
if let index = itemsInStore.index(where: {$0.name == //Index for the row that is to be deleted }) {
itemsInCart.remove(at: index)
}
最佳答案
您必须重新加载表格 View
if let index = itemsInStore.index(where: {$0.name == //Index for the row that is to be deleted }) {
itemsInCart.remove(at: index)
tableView.reloadData()
}
或者 - 更好 - 删除带有动画的特定行
if let index = itemsInStore.index(where: {$0.name == //Index for the row that is to be deleted }) {
itemsInCart.remove(at: index)
let indexPath = IndexPath(row: index, section: 0)
tableView.deleteRows(at: [indexPath], with: .fade)
}
关于swift - 从 tableView 中删除 StructItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51829266/
我希望能够删除 tableView 中的行/项目。 tableView 填充有 struct 结构: struct Items { var name: String = "" var
我是一名优秀的程序员,十分优秀!