2015-03-29 1 views
0

Я пытаюсь удалить пользователя в таблице User из parse с помощью myView. я получаю сообщение об ошибке, когда я это сделать:Swift: Удалить PFUser в Parse From 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 = "" 
} 

Я не понимаю, что проблема. Считаете ли вы, что мы не можем удалить пользователя в таблице User?

Когда я пытаюсь с PFUser.currentUser() он работает, но это просто удалить мой текущий пользователь, и это не то, что я хочу ..

ответ

3

пользователя по умолчанию, не может удалить другой пользователь. Вам необходимо (1) войти в систему как другое другое, (2) изменить разрешение доступа или (3) вызвать функцию CloudCode и выполнить удаление на сервере с помощью главного ключа.

+0

Хммм спасибо за ваш ответ. Я не знаю, как выполнить функцию CloudCode, но я попытаюсь войти в систему как пользователь oser, возможно, когда я попытаюсь удалить их, используя PFUser.currentUser. Но мне не нравится эта идея, я думаю, что это может быть действительно опасно. В противном случае я покажу другой список пользователей в моем представлении таблицы, соответствующий копии пользователя. –