Welcome, Guest
Username Password: Remember me

Detail Cell Customization
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: Detail Cell Customization

Detail Cell Customization 1 year, 7 months ago #1

I have an SCSelectionCell having the title "Choose A Color." When the user taps that cell, I want to be able to have all of the cells of the detail view be different colors. Right now, I'm just using an array for the cell's items.

I've tried using both detailCell.backgroundColor and detailCell.contentView.backgroundColor with no success.


Here is a snip from my viewDidLoad to set up the STV:

[_tableView setBackgroundColor:[UIColor clearColor]];
 
_tableViewModel = [[SCTableViewModel alloc] initWithTableView:_tableView withViewController:self];
 
// Color Selection Cell
SCSelectionCell *colorCell = [SCSelectionCell cellWithText:@"Choose A Color"];
colorCell.items = [NSArray arrayWithObjects:@"Red", @"Blue", nil];
colorCell.allowMultipleSelection = NO;
colorCell.detailTableViewStyle = UITableViewStyleGrouped;
colorCell.selectionStyle = UITableViewCellSelectionStyleGray;
colorCell.autoDismissDetailView = YES;
colorCell.delegate = self;
 
// Create Color section
SCTableViewSection *colorSection = [SCTableViewSection sectionWithHeaderTitle:nil];
 
// Add cells to section
[colorSection addCell:colorCell];
 
// Add section to the tableview model
[_tableViewModel addSection:colorSection]




And here is where I'm catching the detail view and trying to change the cells' colors


- (void)detailViewWillAppearForCell:(SCTableViewCell *) cell  withDetailTableViewModel:(SCTableViewModel *) detailTableViewModel
{
detailTableViewModel.viewController.navigationController.navigationBar.tintColor = [UIColor blackColor];
 
SCTableViewSection *detailSection = [detailTableViewModel sectionAtIndex:0];
 
// Change color of Red cell
SCTableViewCell *detailCell = [detailSection cellAtIndex:0];
detailCell.backgroundColor = [UIColor redColor];
 
// Change color of Blue cell
detailCell = [detailSection cellAtIndex:1];
detailCell.backgroundColor = [UIColor blueColor];
 
UIImageView *bg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bluelinetheme.png"]];
bg.frame = CGRectMake(0.0f, 0.0f, 50.0f, 50.0f);
 
UITableView *tv = detailTableViewModel.modeledTableView;
tv.opaque = NO;
tv.backgroundView = bg;
[tv reloadData];
}
 
  • icyplains
  • OFFLINE
  • Expert Boarder
  • Posts: 133
  • Karma: 5

Re: Detail Cell Customization 1 year, 7 months ago #2

Cells can only be configured this way in their willDisplayCell delegate method. Here is a code sample that illustrates how to setup this delegate for the detail model (please use the latest BETA I've sent you to be able to use the new detailTableViewModel.tag property, otherwise just check that the model isn't the parent model):

 
- (void)detailViewWillAppearForCell:(SCTableViewCell *)cell
withDetailTableViewModel:(SCTableViewModel *)detailTableViewModel
{
detailTableViewModel.delegate = self;
detailTableViewModel.tag = 1;
 
detailTableViewModel.viewController.navigationController.navigationBar.tintColor = [UIColor blackColor];
 
UIImageView *bg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bluelinetheme.png"]];
bg.frame = CGRectMake(0.0f, 0.0f, 50.0f, 50.0f);
 
UITableView *tv = detailTableViewModel.modeledTableView;
tv.opaque = NO;
tv.backgroundView = bg;
[tv reloadData];
}
 
// Don't forget to conform to the SCTableViewModelDelegate for this method to get called
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
willDisplayCell:(SCTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableViewModel.tag != 1) // Check that it's not the parent model
return;
 
switch (indexPath.row) {
case 0:
cell.backgroundColor = [UIColor redColor];
break;
case 1:
cell.backgroundColor = [UIColor blueColor];
break;
}
}
 
 
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Detail Cell Customization 1 year, 7 months ago #3

Thanks Tarek, but I'm getting an error using the tableViewModel.tag. I am using the BETA3 that you sent. I also tried BETA2.


"request for member 'tag' in something not a structure or union"
  • icyplains
  • OFFLINE
  • Expert Boarder
  • Posts: 133
  • Karma: 5

Re: Detail Cell Customization 1 year, 7 months ago #4

It's in beta 4. Apologies, I thought you already had that. Will send it right away, thanks!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Detail Cell Customization 1 year, 7 months ago #5

Cool thanks. Sorry to keep you so busy lately
  • icyplains
  • OFFLINE
  • Expert Boarder
  • Posts: 133
  • Karma: 5

Re: Detail Cell Customization 1 year, 7 months ago #6

No problem at all, just tell me if everything is working well for you now
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72
  • Page:
  • 1
  • 2
Time to create page: 2.09 seconds