Welcome, Guest
Username Password: Remember me

Custom header view in grouped section
(1 viewing) (1) Guest

TOPIC: Custom header view in grouped section

Custom header view in grouped section 1 year, 6 months ago #1

Hi!

I was wondering where (willConfigureCell?) and how i would go about setting a custom header/footer view for a grouped/sectionned tableview with the latest relaese. Can't seem to fin a sample with this customization.

Thanks!
  • codebonbon
  • OFFLINE
  • Expert Boarder
  • Posts: 149
  • Karma: 8

Re: Custom header view in grouped section 1 year, 6 months ago #2

Hi Harold,

To set a custom header/footer view, just set the SCTableViewSection "headerView"/"footerView" properties. Please tell me if you need any more help.
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Custom header view in grouped section 1 year, 6 months ago #3

Hmmm...tried this but the header text label still gets drawn rather then my view. Hi think the problem lies in the sectionHeaderForTitle part. I need multiple grouped sections with custom header/footer views.

 
- (void)tableViewModel:(SCTableViewModel *) tableViewModel willConfigureCell:(SCTableViewCell *) cell forRowAtIndexPath:(NSIndexPath *) indexPath
{
 
SCTableViewSection *section = [tableViewModel sectionAtIndex:0];
section.headerHeight = 50;
 
CustomHeader *header = [[[CustomHeader alloc] init] autorelease];
 
header.lightColor = [UIColor colorWithRed:147.0/255.0 green:105.0/255.0 blue:216.0/255.0 alpha:1.0];
header.darkColor = [UIColor colorWithRed:72.0/255.0 green:22.0/255.0 blue:137.0/255.0 alpha:1.0];
 
section.headerView = header;
 
 
}
 
- (NSString *)tableViewModel:(SCArrayOfItemsModel *)tableViewModel sectionHeaderTitleForItem:(NSObject *)item AtIndex:(NSUInteger)index
{
// Cast not technically neccessary, done just for clarity
MyEntity *managedObject = (MyEntity *)item;
 
NSString *objectName = managedObject.somewhere.street;
 
// Return first charcter of objectName
return [[objectName substringToIndex:1] uppercaseString];
 
}
 


Thanks!
  • codebonbon
  • OFFLINE
  • Expert Boarder
  • Posts: 149
  • Karma: 8

Re: Custom header view in grouped section 1 year, 6 months ago #4

Hmm... actually when i add a new section, my custom section header view doesn't show up. But when i scroll down afterwards it does. Should i move my view code in the willDisplayCell method?

Thanks!
  • codebonbon
  • OFFLINE
  • Expert Boarder
  • Posts: 149
  • Karma: 8

Re: Custom header view in grouped section 1 year, 6 months ago #5

Where are you currently setting up the headerView property? You should be doing this in your view controller's viewDidLoad method (along with the section creation). Also, would you please post some code so that I can try replicating this? Thanks!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Custom header view in grouped section 1 year, 6 months ago #6

Hmmm...


I don't know if viewDidLoad will help since i'm adding new sections with the '+' button, dynamically. As i've posted before here is the code where i setup my header view. Is there some headerView event that i could use?

 
 
- (void)viewDidLoad {
[super viewDidLoad];
 
 
// Set up the edit and add buttons.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
 
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
 
AppDelegate_Shared *appDelegate = [[UIApplication sharedApplication] delegate];
self.managedObjectContext = [appDelegate managedObjectContext];
 
 
// Create a class definition for MyEntity
SCClassDefinition *myEntityClassDef =
[SCClassDefinition definitionWithEntityName:@"MyEntity"
withManagedObjectContext:self.managedObjectContext
withPropertyNames: [NSArray arrayWithObjects:@"prop1",@"prop2", nil]];
 
 
 
 
// Instantiate the tabel model
tableModel = [[SCArrayOfObjectsModel alloc] initWithTableView:self.tableView withViewController:self
withEntityClassDefinition:myEntityClassDef];
tableModel.addButtonItem = self.navigationItem.rightBarButtonItem;
tableModel.autoSortSections = TRUE;
 
 
}
 
- (void)tableViewModel:(SCTableViewModel *) tableViewModel willConfigureCell:(SCTableViewCell *) cell forRowAtIndexPath:(NSIndexPath *) indexPath
{
 
SCTableViewSection *section = [tableViewModel sectionAtIndex:0];
section.headerHeight = 50;
 
CustomHeader *header = [[[CustomHeader alloc] init] autorelease];

header.lightColor = [UIColor colorWithRed:147.0/255.0 green:105.0/255.0 blue:216.0/255.0 alpha:1.0];
header.darkColor = [UIColor colorWithRed:72.0/255.0 green:22.0/255.0 blue:137.0/255.0 alpha:1.0];
 
section.headerView = header;
 
 
}
 
- (NSString *)tableViewModel:(SCArrayOfItemsModel *)tableViewModel sectionHeaderTitleForItem:(NSObject *)item AtIndex:(NSUInteger)index
{
// Cast not technically neccessary, done just for clarity
MyEntity *managedObject = (MyEntity *)item;
 
NSString *objectName = managedObject.somewhere.street;
 
// Return first charcter of objectName
return [[objectName substringToIndex:1] uppercaseString];
 
}
 
  • codebonbon
  • OFFLINE
  • Expert Boarder
  • Posts: 149
  • Karma: 8
Last Edit: 1 year, 6 months ago by codebonbon.
Time to create page: 1.09 seconds