tableView を使用して、ユーザー テーブルのユーザーを解析から削除しようとしています。私がそれをすると、このエラーメッセージが表示されます:
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つのクラスがあります:
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 = ""
}
何が問題なのかわかりません。ユーザーテーブルでユーザーを削除できないと思いますか?
PFUser.currentUser() を試してみると動作しますが、現在のユーザーを削除するだけで、私が望むものではありません..