Question

Well, guys.

I have a problem here, when I try to delete objects at different indexes of one NSMutableArray. I know how init one NSArray of NSIndexPath using method [_tableFavoritos indexPathsForSelectedRows], but I don't know how make a NSIndexSet from this NSArray.

I want to use the method

[arrayFavoritos removeObjectsAtIndexes : (here my NSIndexSet) ];

To solve this.

Or if someone know another way, be welcome.

Thanks...

NSArray *indexesArray = [[NSArray alloc]initWithArray:[_tableFavoritos indexPathsForSelectedRows]];

[arrayFavoritos removeObjectsAtIndexes:];

[_tableFavoritos deleteRowsAtIndexPaths:[_tableFavoritos indexPathsForSelectedRows] withRowAnimation:UITableViewRowAnimationFade];

[_tableFavoritos reloadData];
Was it helpful?

Solution

This should work for you:

NSArray *indexesArray = [[NSArray alloc]initWithArray:[_tableFavoritos indexPathsForSelectedRows]];

NSMutableIndexSet *indexSet = [NSMutableIndexSet new];
[indexesArray enumerateObjectsUsingBlock:^(NSIndexPath *indexPath, NSUInteger idx, BOOL *stop) {
    [indexSet addIndex:indexPath.row];
}];

[arrayFavoritos removeObjectsAtIndexes:indexSet];

[_tableFavoritos deleteRowsAtIndexPaths:[_tableFavoritos indexPathsForSelectedRows] withRowAnimation:UITableViewRowAnimationFade];

[_tableFavoritos reloadData];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top