I have a UITableView
with 4 sections. Three of these sections have a header view.
The header view is a UITableViewCell
, which I am de-queueing as a normal cell in the viewForHeaderInSection:
delegate.
If I insert or delete a row from any section, the other tableview
header cells disappear.
I'm assuming this has something to do with cell reuse, however the cells initially all appear on screen (all three headers appear onscreen at the same time).
I've tried reloading the other sections after the insert or delete, but that doesn't help.
Here's some code:
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { switch (section) { case kSectionCardInformation: case kSectionContactInformation: case kSectionTags: { static NSString *CellIdentifier = @"EditContactHeaderCell"; EditContactHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; return cell; } default: return nil; } }
And here is where I delete the row in the revelant section:
- (void)deleteTag:(CDTag *)tag { [self.tableView beginUpdates]; NSMutableArray *objects = [self.sections objectAtIndex:kSectionTags]; if ([objects containsObject:tag]) { NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[objects indexOfObject:tag] inSection:kSectionTags]; [objects removeObject:tag]; [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationMiddle]; [self.contact deleteTag:tag]; } [self.tableView endUpdates]; }
Any help, greatly appreciated.
If you have a single header in the table then you can use tableHeaderView as below: tableView. tableHeaderView = Header; Or if you have multiple header in table than you need to use Group table instead of plain table.
You can't "hide" a section as such, but you can "delete" it from the table view using the deleteSections:withRowAnimation: method. This will remove it from the view, with an optional animation, without affecting your backing data. (You should, however, update the data anyway so that the section doesn't reappear.)
Just wrap your UITableViewCell into a UIView.
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { switch (section) { case kSectionCardInformation: case kSectionContactInformation: case kSectionTags: { static NSString *CellIdentifier = @"EditContactHeaderCell"; EditContactHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; UIView * view = [[[UIView alloc] init] autorelease]; [view addSubview:cell]; //setup the view's frame: fixed, autolayout, ... return view; } default: return nil; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With