webmagnets webmagnets - 2 years ago 431
iOS Question

How can I check if an indexPath is valid, thus avoiding an "attempt to scroll to invalid index path" error?

How can I check to see whether an indexPath is valid or not?

I want to scroll to an index path, but I sometimes get an error if my collection view's subviews aren't finished loading.

Answer Source

You could check

- numberOfSections
- numberOfItemsInSection: 

of your UICollectionView to see if your indexPath is a valid one.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download