我不止想要上面的功能,而且还想要删除成功后,原来页面是个tableview,怎么让他的tableviewcell里面的按钮显示
时间: 2024-03-20 07:43:37 浏览: 13
根据您的描述,我理解您想要实现的是在删除操作后,使得原本被删除的数据对应的 `tableViewCell` 里面的按钮显示。您可以尝试以下步骤:
1. 在 `tableView(_:cellForRowAt:)` 方法中,为每个 `tableViewCell` 上的按钮设置一个 `tag`,以便后续根据 `tag` 找到对应的按钮。
```
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MyTableViewCell
cell.myButton.tag = indexPath.row
// Configure cell...
return cell
}
```
2. 当执行删除操作时,获取被删除的数据对应的 `tableViewCell` 的 `indexPath`,然后根据 `indexPath` 找到该 `tableViewCell` 上的按钮,并将其显示。
```
func deleteData(at indexPath: IndexPath) {
// Delete data...
tableView.deleteRows(at: [indexPath], with: .automatic)
// Show button...
let cell = tableView.cellForRow(at: indexPath) as! MyTableViewCell
let button = cell.myButton
button.isHidden = false
}
```
请注意,在以上代码示例中,`MyTableViewCell` 和 `myButton` 分别代表您自己定义的 `UITableViewCell` 子类和其中的按钮。您需要将其替换为您实际的命名。