gpt4 book ai didi

ios - 如何限制只对某些用户删除 TableView 中的行?

转载 作者:行者123 更新时间:2023-11-28 06:43:34 25 4
gpt4 key购买 nike

我的问题如下。我创建了一个应用程序,允许用户向 TableViewController 中的行添加帖子。它还允许他们通过检查当前用户是否与创建帖子的用户具有相同的 ID 来仅删除具有 UITableViewCellEditingStyle 的帖子。不幸的是,这种编辑单元格的方式也允许尝试删除其他用户的帖子。我想让删除按钮只在用户滑动他们的帖子时出现。我附上an image of the button我一直在谈论。

最佳答案

你可以这样做:

如果您没有 UITableViewCell 的自定义类:

override func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
if owner[indexPath.row] == me {
return .Delete
}
else {
return .None
}
}

或者如果您有 UITableViewCell 的自定义类,那么:

override func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
if (tableView.cellForRowAtIndexPath(indexPath) as! YourTableViewCell).owner == me {
return .Delete
}
else {
return .None
}
}

关于ios - 如何限制只对某些用户删除 TableView 中的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37217071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com