Welcome, Guest
Username Password: Remember me

Changing ICons based upon conditions
(1 viewing) (1) Guest

TOPIC: Changing ICons based upon conditions

Changing ICons based upon conditions 1 year, 4 months ago #1

Evening

I just wanted to make sure it was possible to change the icon/ image on the left hand side of the cell depending on a condition that was met.

For example, if I pick A, a Red Dot appears, if I pick B, A Yellow one appears and if I pick C, a yellow dot appears.

Iain
  • ihmunro
  • OFFLINE
  • Expert Boarder
  • Posts: 135
  • Karma: 0

Re: Changing ICons based upon conditions 1 year, 4 months ago #2

Hi Iain,

Are you talking about an SCSelectionCell here, where you want to modify its image according to the selected item?
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: Changing ICons based upon conditions 1 year, 4 months ago #3

Hi Tarek

I could do it there, but was thinking at the high level as well where I have the code:

- (void)tableViewModel:(SCTableViewModel *) tableViewModel willDisplayCell:(SCTableViewCell *) cell forRowAtIndexPath:(NSIndexPath *) indexPath
{
cell.imageView.image = [UIImage imageNamed:@"task.png"];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;


So where the task.png image goes, I would want to see RedDot.png, YellowDot.png etc depending on what was picked.

Iain
  • ihmunro
  • OFFLINE
  • Expert Boarder
  • Posts: 135
  • Karma: 0

Re: Changing ICons based upon conditions 1 year, 4 months ago #4

What type of cell is this? Also, is it auto generated via a class definition, or have you added it to the section yourself?
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: Changing ICons based upon conditions 1 year, 4 months ago #5

Hi Tarek

I used some of your code from your custom app where you had the task.png added.

I added some additional code to give me the blue arrow.

The code is located in the RooViewController.m file.

Iain
  • ihmunro
  • OFFLINE
  • Expert Boarder
  • Posts: 135
  • Karma: 0

Re: Changing ICons based upon conditions 1 year, 4 months ago #6

Hi Iain,

Assuming that you're reusing code from our CustomizationViewController.m file, you'll need to implement both of these SCTableViewModelDelegate methods:

 
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
willDisplayCell:(SCTableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath
{
if([cell isKindOfClass:[SCSelectionCell class]])
{
SCSelectionCell *selectionCell = (SCSelectionCell *)cell;
NSUInteger selectedIndex = [selectionCell.selectedItemIndex intValue];
switch(selectedIndex)
{
case -1: // no selection
selectionCell.imageView.image = nil;
break;
case 0:
selectionCell.imageView.image = [UIImage imageNamed:@"RedDot.png"];;
break;
case 1:
selectionCell.imageView.image = [UIImage imageNamed:@"YellowDot.png"];;
break;
}
}
}
 
// Method gets called whenever a cell's value changes
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
valueChangedForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Place here the exact same code as in the above willDisplayCell method
// (you may want to have the code in its own method and call it from both methods)
}
 


Hope this helps!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72
Time to create page: 1.00 seconds