Swift : 从 TableView 中删除 PFUser
Swift : Delete PFUser in Parse From a TableView
我正在尝试从 table 视图的解析中删除用户 table 中的用户。
我在执行此操作时收到此错误消息:
2015-03-29 15:15:00.385 IOS-EHPAD[1717:651792] -[UIApplication endIgnoringInteractionEvents] called without matching -beginIgnoringInteractionEvents. Ignoring.
2015-03-29 15:15:04.221 IOS-EHPAD[1717:651792] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '**User cannot be deleted unless they have been authenticated via logIn or signUp**'
*** First throw call stack:
(0x1854ea530 0x1964740e4 0x1854ea470 0x10015844c 0x100113000 0x10016b668 0x1001149a8 0x100114b94 0x1000d7628 0x1000d7884 0x189efbbd4 0x189fe5094 0x189d2ca14 0x189d15d08 0x189d2c3b0 0x189cebec8 0x189d25ed8 0x189d25578 0x189cf8e60 0x189f9846c 0x189cf73d0 0x1854a2d34 0x1854a1fd8 0x1854a0088 0x1853cd1f4 0x18e7f76fc 0x189d5e10c 0x1000cc8e4 0x1000cc9fc 0x196af2a08)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
有我的2 class :
import UIKit
class ListeUtilisateursPFQueryTableViewController: UITableViewController, UISearchBarDelegate {
var images = [NSData]()
var users = [""]
var status = [""]
var objectId = [""]
var userObjects: NSMutableArray = NSMutableArray()
// Table search bar
@IBOutlet weak var searchBar: UISearchBar!
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return userObjects.count
}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if (editingStyle == UITableViewCellEditingStyle.Delete) {
let objectToDelete:PFUser = userObjects.objectAtIndex(indexPath.row) as PFUser
objectToDelete.deleteInBackgroundWithBlock {
(success: Bool, error: NSError!) -> Void in
if (success) {
// Force a reload of the table - fetching fresh data from Parse platform
self.loadData()
} else {
println(error)
// There was a problem, check error.description
}
}
self.tableView.reloadData()
}
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:CustomTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as CustomTableViewCell
cell.nomUtilisateur.text = users[indexPath.row]
cell.statusUtilisateur.text = objectId[indexPath.row]
return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var cell:UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!
}
// Override to support conditional editing of the table view.
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return NO if you do not want the specified item to be editable.
return true
}
override func viewDidLoad() {
super.viewDidLoad()
loadData()
}
func loadData() {
userObjects.removeAllObjects()
users.removeAll(keepCapacity: true)
status.removeAll(keepCapacity: true)
objectId.removeAll(keepCapacity: true)
var findUser: PFQuery = PFUser.query()
findUser.findObjectsInBackgroundWithBlock{
(objects:[AnyObject]!, error:NSError!) -> Void in
for object in objects {
let user: PFObject = object as PFObject
self.userObjects.addObject(user)
self.users.append(object.username)
self.status.append(object.valueForKey("status") as String)
self.objectId.append(object.valueForKey("objectId") as String)
}
let array:NSArray = self.userObjects.reverseObjectEnumerator().allObjects
self.userObjects = NSMutableArray(array: array)
self.tableView.reloadData()
self.refreshControl?.endRefreshing()
}
}
override func viewDidAppear(animated: Bool) {
// Refresh the table to ensure any data changes are displayed
tableView.reloadData()
}
}
还有我的自定义单元格:
import UIKit
class CustomTableViewCell:UITableViewCell {
@IBOutlet weak var nomUtilisateur: UILabel!
@IBOutlet weak var statusUtilisateur: UILabel!
@IBOutlet weak var photoUtilisateur: PFImageView!
var userId = ""
}
我不明白这是什么问题。您认为我们无法删除用户 table 中的用户吗?
当我尝试使用 PFUser.currentUser() 时,它起作用了,但它只是删除了我当前的用户,这不是我想要的..
默认情况下,一个用户不能删除另一个用户。您将需要 (1) 以另一个身份登录,(2) 更改访问权限,或 (3) 调用 CloudCode 函数并使用主密钥在服务器上执行删除。
我正在尝试从 table 视图的解析中删除用户 table 中的用户。 我在执行此操作时收到此错误消息:
2015-03-29 15:15:00.385 IOS-EHPAD[1717:651792] -[UIApplication endIgnoringInteractionEvents] called without matching -beginIgnoringInteractionEvents. Ignoring.
2015-03-29 15:15:04.221 IOS-EHPAD[1717:651792] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '**User cannot be deleted unless they have been authenticated via logIn or signUp**'
*** First throw call stack:
(0x1854ea530 0x1964740e4 0x1854ea470 0x10015844c 0x100113000 0x10016b668 0x1001149a8 0x100114b94 0x1000d7628 0x1000d7884 0x189efbbd4 0x189fe5094 0x189d2ca14 0x189d15d08 0x189d2c3b0 0x189cebec8 0x189d25ed8 0x189d25578 0x189cf8e60 0x189f9846c 0x189cf73d0 0x1854a2d34 0x1854a1fd8 0x1854a0088 0x1853cd1f4 0x18e7f76fc 0x189d5e10c 0x1000cc8e4 0x1000cc9fc 0x196af2a08)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
有我的2 class :
import UIKit
class ListeUtilisateursPFQueryTableViewController: UITableViewController, UISearchBarDelegate {
var images = [NSData]()
var users = [""]
var status = [""]
var objectId = [""]
var userObjects: NSMutableArray = NSMutableArray()
// Table search bar
@IBOutlet weak var searchBar: UISearchBar!
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return userObjects.count
}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if (editingStyle == UITableViewCellEditingStyle.Delete) {
let objectToDelete:PFUser = userObjects.objectAtIndex(indexPath.row) as PFUser
objectToDelete.deleteInBackgroundWithBlock {
(success: Bool, error: NSError!) -> Void in
if (success) {
// Force a reload of the table - fetching fresh data from Parse platform
self.loadData()
} else {
println(error)
// There was a problem, check error.description
}
}
self.tableView.reloadData()
}
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:CustomTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as CustomTableViewCell
cell.nomUtilisateur.text = users[indexPath.row]
cell.statusUtilisateur.text = objectId[indexPath.row]
return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var cell:UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!
}
// Override to support conditional editing of the table view.
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return NO if you do not want the specified item to be editable.
return true
}
override func viewDidLoad() {
super.viewDidLoad()
loadData()
}
func loadData() {
userObjects.removeAllObjects()
users.removeAll(keepCapacity: true)
status.removeAll(keepCapacity: true)
objectId.removeAll(keepCapacity: true)
var findUser: PFQuery = PFUser.query()
findUser.findObjectsInBackgroundWithBlock{
(objects:[AnyObject]!, error:NSError!) -> Void in
for object in objects {
let user: PFObject = object as PFObject
self.userObjects.addObject(user)
self.users.append(object.username)
self.status.append(object.valueForKey("status") as String)
self.objectId.append(object.valueForKey("objectId") as String)
}
let array:NSArray = self.userObjects.reverseObjectEnumerator().allObjects
self.userObjects = NSMutableArray(array: array)
self.tableView.reloadData()
self.refreshControl?.endRefreshing()
}
}
override func viewDidAppear(animated: Bool) {
// Refresh the table to ensure any data changes are displayed
tableView.reloadData()
}
}
还有我的自定义单元格:
import UIKit
class CustomTableViewCell:UITableViewCell {
@IBOutlet weak var nomUtilisateur: UILabel!
@IBOutlet weak var statusUtilisateur: UILabel!
@IBOutlet weak var photoUtilisateur: PFImageView!
var userId = ""
}
我不明白这是什么问题。您认为我们无法删除用户 table 中的用户吗?
当我尝试使用 PFUser.currentUser() 时,它起作用了,但它只是删除了我当前的用户,这不是我想要的..
默认情况下,一个用户不能删除另一个用户。您将需要 (1) 以另一个身份登录,(2) 更改访问权限,或 (3) 调用 CloudCode 函数并使用主密钥在服务器上执行删除。