I have a tableView with multiple sections.
Now I want to reload all sections of tableView except the first one (because it's static and doesn't change).
I now I can reload sections by this method:
reloadSections(IndexSet, with: UITableView.RowAnimation)
but it requires the number of sections and in my app this is dynamic and changes in time.
I can only say reload whatever exist after first section.
I thought I should define a IndexSet
somehow like this:
NSIndexSet *indexSet = [NSIndexPath indexPathWithIndexes:(NSUInteger[]){1, ... } length:???];
and I don't know how can I do that!
Any ideas or suggestion would be greatly appreciated.
update
This is the numberOfSectionsInTableView
implementation:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
// Inbox Segment
if (self.selectedIndex == 0) {
if (self.inboxArray.count > 0) {
return self.inboxArray.count + 2;
}
}
// Sent Segment
else if (self.selectedIndex == 1) {
if (self.sentArray.count > 0) {
return self.sentArray.count + 2;
}
}
// Outbox Segment
else if (self.selectedIndex == 2) {
if (self.outboxArray.count > 0) {
return self.outboxArray.count + 2;
}
}
// Spam Segment
else if (self.selectedIndex == 3) {
if (self.spamArray.count > 0) {
return self.spamArray.count + 2;
}
}
// Trash Segment
else if (self.selectedIndex == 4) {
if (self.trashArray.count > 0) {
return self.trashArray.count + 2;
}
}
return 1;
}
Assuming you know the amount of sections:
NSIndexSet *sectionsIndexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, self.sections.count - 1)]
[self.tableView reloadSections:sectionsIndexSet withRowAnimation:UITableViewRowAnimationNone];
Swift:
let sectionsIndexSet = IndexSet(1..<sections.count)
tableView.reloadSections(sectionsIndexSet, with: .none)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.