1

Parse Server: 2.2.17 (self hosted)

Parse-SDK-iOS-OSX: 1.14.2

ParseUI-iOS Version: 1.2.0

Xcode 7.3.1, Swift

I'm new at IOS Programming (20 weeks) and build an App for fun and learning.

In one of a lot of TableViewControllers with sections, i like to call a editActionsForRowAtIndexPath. This throws an error, when swipe to left:

2016-08-12 18:14:44.967 myParseCustomLoginTest[54158:729475] * Assertion failure in -[UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.60.7/UITableView.m:1422 2016-08-12 18:14:44.974 myParseCustomLoginTest[54158:729475] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete row 68 from section 0 which only contains 4 rows before the update'

Info:

0) If i swipe on the first section, the error throws.

1) Yes, it's right, in my first section, i have 4 rows.

2) I can't swipe to the left on the following sections. I can only swipe on the first section.

3) The table, sections and rows itself are fine (like the source data from Parse Server).

4) The same code for the editActionsForRowAtIndexPath is working fine for the same table without sections.

Code: class MenuSectionedPFQueryTableViewController: PFQueryTableViewController -> I think it's working fine, because the table, sections and rows are fine.

extension MenuSectionedPFQueryTableViewController numberOfSectionsInTableView numberOfRowsInSection titleForHeaderInSection cellForRowAtIndexPath -> I think it's working fine to, because the table, sections and rows are fine.

Inside the extension MenuSectionedPFQueryTableViewController i have this code:

override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool{
    return indexPath.section == 0 ? true : false
}

override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {

    // Add to diary slider
    let shareAction = UITableViewRowAction(style: .Normal, title: "Add to diary") { (action: UITableViewRowAction, indexPath: NSIndexPath) in
        // create menuItem object
        let menuItem = self.objects![indexPath.row]

        // create menu object
        let menuObject = PFObject(className: "ffdUserDiary")

        // reference menu to pointer ffdDB2Pointer
        let ex = PFObject(className: "ffdDB")
        ex.objectId = menuItem.objectId
        print(menuItem.objectId)
        menuObject.setObject(ex, forKey: "ffdDBPointer")

        // reference current user to pointer userPointer
        menuObject["userPointer"] = PFUser.currentUser()

        // add x + y to diary
        menuObject["x"] = menuItem.objectForKey("x")
        menuObject["y"] = menuItem.objectForKey("y")

        // save menuObject
        // menuObject.saveEventually()
        menuObject.saveInBackgroundWithBlock { (success, error) in
            if let error = error {
                print("error: \(error.localizedDescription)")
            } else {
                print("success: \(success)")
            }
        }

        // tableView.reloadData()
    }
    shareAction.backgroundColor = UIColor.redColor()
    return [shareAction]
}

I think it is an error with the indexPath, but can't fix it. Any ideas?

Pranav Wadhwa
  • 7,666
  • 6
  • 39
  • 61
  • Looks like you are trying to reload rows in the table view while it is refreshing. Try to see where are you doing that. – Santosh Aug 12 '16 at 16:56
  • I like parse for the backend stuff, networking and many supporting platform. I am iOS developer and using PFQueryTableView only brought me problems, it overrides many methods and you will end up googling what exactly does it override, but you can spend this time googling how to do it in regular TableView... – Mazel Tov Aug 12 '16 at 20:51
  • I have fixed it: In tableViews with sections i have to use "let menuItem = objectAtIndexPath(indexPath)" and not "let menuItem = self.objects![indexPath.row]". In tableViews without sections, i can use "let menuItem = self.objects![indexPath.row]". – Calvin Orchiz Aug 15 '16 at 04:56

0 Answers0