NSIndexSet indexSetWithIndexesInRange
+ (id)indexSetWithIndexesInRange:(NSRange)indexRange
Parameters
indexRange
An index range.
Return Value of [NSIndexSet indexSetWithIndexesInRange]
NSIndexSet object containing indexRange.
NSIndexSet indexSetWithIndexesInRange example.
If the indexes are consecutive like in your example, you can use this:
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, 3)];
If not, create a mutable index set and add the indexes (or ranges) one by one:
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:3];
[indexSet addIndex:5];
[indexSet addIndex:8];
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, 3)];
If not, create a mutable index set and add the indexes (or ranges) one by one:
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:3];
[indexSet addIndex:5];
[indexSet addIndex:8];
Example of [NSIndexSet indexSetWithIndexesInRange].
NSRange range = NSMakeRange(0, 1);
NSIndexSet *section = [NSIndexSet indexSetWithIndexesInRange:range];
[self.tableView reloadSections:section withRowAnimation:UITableViewRowAnimationNone];
This will reload the first section. I prefer to have a category on UITableView and just call this method:
[self.tableView reloadSection:0 withRowAnimation:UITableViewRowAnimationNone];
My category method looks like this:
@implementation UITableView (DUExtensions)
- (void) reloadSectionDU:(NSInteger)section withRowAnimation:(UITableViewRowAnimation)rowAnimation {
NSRange range = NSMakeRange(section, 1);
NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
[self reloadSections:sectionToReload withRowAnimation:rowAnimation];
}
NSIndexSet *section = [NSIndexSet indexSetWithIndexesInRange:range];
[self.tableView reloadSections:section withRowAnimation:UITableViewRowAnimationNone];
This will reload the first section. I prefer to have a category on UITableView and just call this method:
[self.tableView reloadSection:0 withRowAnimation:UITableViewRowAnimationNone];
My category method looks like this:
@implementation UITableView (DUExtensions)
- (void) reloadSectionDU:(NSInteger)section withRowAnimation:(UITableViewRowAnimation)rowAnimation {
NSRange range = NSMakeRange(section, 1);
NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
[self reloadSections:sectionToReload withRowAnimation:rowAnimation];
}
NSIndexSet indexSetWithIndexesInRange example.
int z;
z = (int)self.specificPosition;
// Start adding at index position z and secondArray has count items
NSRange range = NSMakeRange(z, [secondArray count]);
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:range];
[self.firstArray insertObjects:secondArray atIndexes:indexSet];
z = (int)self.specificPosition;
// Start adding at index position z and secondArray has count items
NSRange range = NSMakeRange(z, [secondArray count]);
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:range];
[self.firstArray insertObjects:secondArray atIndexes:indexSet];