Welcome, Guest
Username Password: Remember me
  • Page:
  • 1

TOPIC: Splitting Sections.

Splitting Sections. 1 year, 2 months ago #1

Hi again. I have this code that splits a tableview into two sections, one with a name field, and the second with everything else..



- (void)tableViewModel:(SCTableViewModel *)tableViewModel 
detailViewWillAppearForSectionAtIndex:(NSUInteger)index
withDetailTableViewModel:(SCTableViewModel *)detailTableViewModel
{
NSLog(@"%s", __FUNCTION__);
 
//************* Set a tag that is equivalent to the model's level in the heirarchy (used later to identify the model)
detailTableViewModel.tag = tableViewModel.tag + 1;
 
//************* Set the delegate for the detail model so that delegate methods would be called
detailTableViewModel.delegate = self;
 
if(tableViewModel.tag == 0) // main model
{
SCTableViewSection *verbSection = [detailTableViewModel sectionAtIndex:0];
SCTableViewCell *nameCell = [verbSection cellAtIndex:0];
SCTableViewCell *transCell = [verbSection cellAtIndex:1];
 
// Create new section
SCObjectSection *newSection = [SCObjectSection section];
newSection.commitCellChangesLive = FALSE; // allow user to cancel changes by tapping Cancel
[newSection addCell:nameCell];
[newSection addCell:transCell];
[detailTableViewModel insertSection:newSection atIndex:0];
 
// Remove the nameCell from the original section
[verbSection removeCellAtIndex:0];
[verbSection removeCellAtIndex:1];
}
}
 
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
detailViewWillAppearForRowAtIndexPath:(NSIndexPath *)indexPath
withDetailTableViewModel:(SCTableViewModel *) detailTableViewModel
{
[self tableViewModel:tableViewModel detailViewWillAppearForSectionAtIndex:indexPath.section
withDetailTableViewModel:detailTableViewModel];
}
 


I have mucked around with it, but I would like to know how to have two or three elements in the first section, and the remainder in the second..

Thanks !!
Last Edit: 1 year, 2 months ago by tarekskr.

Re: Splitting Sections. 1 year, 2 months ago #2

Hi David,

Your code actually has a bug in these couple of lines:

 
...
[verbSection removeCellAtIndex:0];
[verbSection removeCellAtIndex:1];
...
 


When you remove the cell at index zero, the next cell to be removed is now at index zero too, and not index one. So the code should be:

 
...
[verbSection removeCellAtIndex:0];
[verbSection removeCellAtIndex:0];
...
 


Or if you'd like to avoid the confusion:

 
...
[verbSection removeCellAtIndex:1];
[verbSection removeCellAtIndex:0];
...
 


Hope this helps!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72
Last Edit: 1 year, 2 months ago by tarekskr.

Re: Splitting Sections. 1 year, 2 months ago #3

That did it.. Thanks Tarek..
  • Page:
  • 1
Time to create page: 0.90 seconds