isEqual doesn’t always work for NSIndexPath? What can I use in its place?

As of iOS 5 you can just use isEqual: (see comments) Try [indexPath1 compare: indexPath2] == NSOrderedSame. Maybe you found a bug in NSIndexPath. If you try to create a new NSIndexPath with a path that already exists you should get that one instead. So isEqual: probably just compares the pointers and not the actual … Read more

How to compare two NSIndexPaths?

Almost all Objective-C objects can be compared using the isEqual: method. So, to test equality, you just need [itemCategoryIndexPath isEqual:indexPath], and you’re good to go. Now, this works because NSObject implements isEqual:, so all objects automatically have that method, but if a certain class doesn’t override it, isEqual: will just compare object pointers. In the … Read more

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

You could check – numberOfSections – numberOfItemsInSection: of your UICollection​View​Data​Source to see if your indexPath is a valid one. E.g. extension UICollectionView { func isValid(indexPath: IndexPath) -> Bool { guard indexPath.section < numberOfSections, indexPath.row < numberOfItems(inSection: indexPath.section) else { return false } return true } }

How can I get a uitableViewCell by indexPath?

[(UITableViewCell *)[(UITableView *)self cellForRowAtIndexPath:nowIndex] will give you uitableviewcell. But I am not sure what exactly you are asking for! Because you have this code and still you asking how to get uitableviewcell. Some more information will help to answer you 🙂 ADD: Here is an alternate syntax that achieves the same thing without the cast. … Read more

NSIndexpath.item vs NSIndexpath.row

Okay, nobody has given a good answer here. Inside NSIndexPath, the indexes are stored in a simple c array called “_indexes” defined as NSUInteger* and the length of the array is stored in “_length” defined as NSUInteger. The accessor “section” is an alias to “_indexes[0]” and both “item” and “row” are aliases to “_indexes[1]”. Thus … Read more

Refresh certain row of UITableView based on Int in Swift

You can create an NSIndexPath using the row and section number then reload it like so: let indexPath = NSIndexPath(forRow: rowNumber, inSection: 0) tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Top) In this example, I’ve assumed that your table only has one section (i.e. 0) but you may change that value accordingly. Update for Swift 3.0: let indexPath = IndexPath(item: … Read more

tech