I have created an editable UITableView that supports several custom UITableViewCells of my own design. Whenever the user creates a new record or modifies an existing record, they use this UITableView. I have the table view sectioned into groups of tableViewCells using a Grouped Style table view.
When the user is editing a record, I do not want section 1 to display. To achieve this I return 0 when the numberOfRowsInSection method is called. Everything works okay, however there is a “slight visual gap” between section 0 and section 2 that I would like to eliminate if possible. I want to avoid recoding the table view controller to handle indexPaths dynamically. Many of my indexPaths (sections & rows) are hard-coded.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
printf("CustomEntryViewController, -tableView:numberOfRowsInSection:\n");
if (tableView == self.customEntryTableView) {
if (section == 0)
return 1;
else if (section == 1) {
if ([self.entryMode isEqualToString:@"ADD"])
return 2;
else if ([self.entryMode isEqualToString:@"EDIT"])
return 0;
}
else if (section == 2)
return 1;
else if (section == 3)
return 1;
else if (section == 4 && self.uisegQuantityAnswer.selectedSegmentIndex == 0)
return 1;
}
return 0;
}
Thanks in advance.
I found a workaround to the problem. I created two helper methods in my view controller to virtualize the sections that get passed to me by the tableView delegates. The virtual sections cause the logic I’ve written to be skipped over whenever I intend to disable a section in my table view.
I then make a call to one of the above methods throughout the rest of the application.
In addition to this I also modified -tableView:numberOfSectionsInTableView: method to return the correct number of sections per ADD versus EDIT mode.
Since this is just a workaround I will keep this question marked unanswered.