Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on Delete #192

Closed
grifas opened this issue May 4, 2018 · 13 comments
Closed

Crash on Delete #192

grifas opened this issue May 4, 2018 · 13 comments

Comments

@grifas
Copy link

grifas commented May 4, 2018

In my project, I'm getting a crash when I try to delete an item. So I tried with your example with my configuration which is having number of section equals to emails.count and just one row in each section corresponding to the item. Of course I changed indexPath.row by indexPath.section in the right place.

It is possible to delete a row in a section and if it's the last row, delete in the same time the section ?

@grifas grifas closed this as completed May 4, 2018
@Mijail
Copy link

Mijail commented Jun 25, 2018

It crashes because the action fulfill calls self.delegate?.swipeController(self, didDeleteSwipeableAt: indexPath)
and that delegate does this:
tableView?.deleteRows(at: [indexPath], with: .none)
And it doesn't delete the section if it is the last row of it, so yes there should be a check if the element is the last one of the section.

@kurabi
Copy link
Member

kurabi commented Jun 26, 2018

@Mijail Please submit a PR.

@Mijail
Copy link

Mijail commented Jul 4, 2018

I can't do it right now, but I think this issue should be open. I will work on it when I can.

@kurabi
Copy link
Member

kurabi commented Jul 4, 2018

I don’t see this crash occurring in the example mail app. So I am not clear on what the issue is.

@Mijail
Copy link

Mijail commented Jul 5, 2018

If I recall the example only has 1 section, the way to test it is having more than one. (numberOfSections(in tableView: UITableView) )

@kurabi
Copy link
Member

kurabi commented Jul 6, 2018

@Mijail I tried that. Didn't work either.

@weakfl
Copy link

weakfl commented Aug 20, 2018

I've got the same issue:

  • collectionview with 2 sections
  • deleting last item in section 0 -> crashes in SwipeCollectionViewCell.swift, line 238:
    func swipeController(_ controller: SwipeController, didDeleteSwipeableAt indexPath: IndexPath) {
        collectionView?.deleteItems(at: [indexPath])
    }

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSDictionaryM setObject:forKey:]: key cannot be nil'

@kurabi
Copy link
Member

kurabi commented Aug 20, 2018

@weakfl Thats not your issue.

@weakfl
Copy link

weakfl commented Aug 20, 2018

@kurabi Does it matter?

FWIW, it's an iOS bug anyway. I was able to work around the issue by using fulfill(with: .reset) and using collectionView.reloadData() instead of collectionView.performBatchUpdates if I'm dealing with the last item in the section...

@weakfl
Copy link

weakfl commented Aug 21, 2018

I didn't really like the collectionView.reloadData() solution because of the missing animation, so I've debugged this a little further.

It turns out the crash is triggered by returning CGSize.zero for a supplementary view during deletion. Returning CGSize(width: collectionView.bounds.size.width, height: CGFloat.leastNonzeroMagnitude) is a better workaround for the issue, as it will allow to run performBatchUpdates without problems.

@kurabi So it's definetely not an issue of SwipeCellKit (which is is a wonderful library btw).

@APvanGrootel
Copy link

Hi. I think the crash happens when didDeleteSwipeableAt is calling deleteRows when there is only one row inside a section. When this is the case, it should call deleteSections

@dbogatz
Copy link

dbogatz commented Jan 7, 2020

@weakfl thanks for support. But where should I add CGSize(width: collectionView.bounds.size.width, height: CGFloat.leastNonzeroMagnitude)?
Wouldn't it better if the library adds a check for last row?

@weakfl
Copy link

weakfl commented Jan 7, 2020

@dbogatz

But where should I add CGSize(width: collectionView.bounds.size.width, height: CGFloat.leastNonzeroMagnitude)?

Depends on your layout. If you're using UICollectionViewFlowLayout for example, you'll have to return this as referenceSizeForHeaderInSection.

Wouldn't it better if the library adds a check for last row?

That's debatable ;) See @APvanGrootel's comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants