Welcome, Guest
Username Password: Remember me

Adding a custom cell to the root item
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: Adding a custom cell to the root item

Adding a custom cell to the root item 1 year, 3 months ago #1

Hi!

I was wondering how to add a custom cell to the root tableview (the first table view you tap an item to see it's detail)? I've only seen some samples to add them in the detail view. I could probably emulate this with the section header/view but i'd like a more "sensible" way of doing this.

Thanks!
  • codebonbon
  • OFFLINE
  • Expert Boarder
  • Posts: 147
  • Karma: 7

Re: Adding a custom cell to the root item 1 year, 2 months ago #2

Hi Tarek!

I've managed to simulate this with the header and footer section of grouped cell. I do wish though it was easier to add custom cell at the root tableview for an entity, This seems to be only possible in detail views.

Thanks!
  • codebonbon
  • OFFLINE
  • Expert Boarder
  • Posts: 147
  • Karma: 7

Re: Adding a custom cell to the root item 1 year, 2 months ago #3

Thanks for the suggestion Harold, I'll add this to our feature requests.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: Adding a custom cell to the root item 1 year, 1 month ago #4

Hi again!

I was wondering if there is still a way to do this (workaround). I tried adding my custom cell/view in the tableViewModel:sectionGenerated:atIndex: method but to no avail. Was able to emulate what i wanted to do by setting a custom view in the footer view but they sometimes don't get redrawn on certain tableview events. I know this can be done but don't seem to figure how to.

Thanks!
 
- (void)tableViewModel:(SCArrayOfItemsModel *) tableViewModel
sectionGenerated:(SCTableViewSection *) section
atIndex:(NSInteger) index
{
SCControlCell *cell = [SCControlCell cellWithText:@""];
cell.backgroundColor = [UIColor greenColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.height = 100;
 
UISegmentedControl *ctl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"A",@"B", nil]];
[cell.contentView addSubview:ctl];
[section addCell:cell];
 
}
 
 
  • codebonbon
  • OFFLINE
  • Expert Boarder
  • Posts: 147
  • Karma: 7
Last Edit: 1 year, 1 month ago by codebonbon.

Re: Adding a custom cell to the root item 1 year, 1 month ago #5

Hi Harold,

Adding cells to an SCArrayOfObjectsSection/Model must be done through their "items" array.

In the case you need to provide a custom action when this custom cell is added, you also need to implement the didSelectRowAtIndexPath method.

 
- (void)tableViewModel:(SCTableViewModel *)tableViewModel didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Assuming the custom cell is at index zero
if(index.row == 0)
{
// do custom action
}
else
{
SCArrayOfObjectsSection *section = (SCArrayOfObjectsSection *)[tableViewModel sectionAtIndex:indexPath.section];
[section dispatchSelectRowAtIndexPathEvent:indexPath];
}
}
 


Please tell me if this works well for you Harold.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: Adding a custom cell to the root item 1 year, 1 month ago #6

Hi again Tarek!

In the same line of thought there seems to be an issue with the deletion of section footerviews when a single item section is modified. I've traced this to that bit of code that i changed as below:

SCTableViewModel.m

 
- (void)itemModified:(NSObject *)item inSection:(SCArrayOfItemsSection *)section
{
NSUInteger oldSectionIndex = [self indexForSection:section];
NSUInteger newSectionIndex = [self getSectionIndexForItem:item];
 
if(oldSectionIndex == newSectionIndex)
{
[section itemModified:item];
}
else
{
 
// My hack ;-)
if([section isKindOfClass:[SCArrayOfObjectsSection class]])
{
[self removeSectionAtIndex:oldSectionIndex];
[self.modeledTableView deleteSections:[NSIndexSet indexSetWithIndex:oldSectionIndex]
withRowAnimation:UITableViewRowAnimationRight];
}
else
{
// remove item from old section
NSIndexPath *oldIndexPath =
[NSIndexPath indexPathForRow:[section.items indexOfObjectIdenticalTo:item]
inSection:oldSectionIndex];
[section.items removeObjectAtIndex:oldIndexPath.row];
[self.modeledTableView
deleteRowsAtIndexPaths:[NSArray arrayWithObject:oldIndexPath]
withRowAnimation:UITableViewRowAnimationRight];
}
 
[item retain];
[self.items removeObjectIdenticalTo:item];
// add the item from scratch
[self addNewItem:item];
[item release];
}
}
 
 
  • codebonbon
  • OFFLINE
  • Expert Boarder
  • Posts: 147
  • Karma: 7
Last Edit: 1 year, 1 month ago by codebonbon.
  • Page:
  • 1
  • 2
Time to create page: 2.05 seconds