-1

I am using UITableView in my application and I have created custom cell in the file DealsCC.xib and when cell is tapped the color of the cell should be changed to blue but it does not happen in my code. I write the code as follows:

static NSString *MyIdentifier = @"dealsCC";
    dealsCC *cell = (dealsCC *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    [cell selectionStyle:UITableViewCellSelectionStyleBlue];

I want to mention that in the line

[cell selectionStyle:UITableViewCellSelectionStyleBlue];

warning msg exists and it is "dealsCC may not respond to -selectionStyle"

plz help me to solve this problem thanx in advance.

iPhone
  • 4,092
  • 3
  • 34
  • 58

3 Answers3

1

please see the following stackoverflow links,please check whether you have followed correclty them 1)link1 2)link2 3)enter link description here

Community
  • 1
  • 1
nameless
  • 809
  • 3
  • 9
  • 27
1

Try this in your custom class for the table view cell

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
       self.selectionStyle = UITableViewCellSelectionStyleBlue;
       [super setSelected:selected animated:animated];

}

The warning is because the method should be

[cell setSelectionStyle:UITableViewCellSelectionStyleBlue];

and not [cell selectionStyle:UITableViewCellSelectionStyleBlue];

visakh7
  • 26,380
  • 8
  • 55
  • 69
0

Use cell.selectionStyle = UITableViewCellSelectionStyleGray; for changing the style of the cell selection. But here the selectionStyle only takes input of UITableViewCellSelectionStyle type.

For changing Color you need to use Image. Use selectedBackgroundView.image property and Follow the tutorial Link

Or you can also try

    cell.selectedBackgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
    cell.selectedBackgroundView.backgroundColor = [UIColor redColor];

EDIT:

OK I am updating code in case you have any other controls on the cell, then you can try below code.

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     static NSString *CellIdentifier = @"myCellId";
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
     if (cell == nil) {
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
     UIView *v = [[[UIView alloc] init] autorelease];
     v.backgroundColor = [UIColor redColor]; // any color of your choice.
     cell.selectedBackgroundView = v;
      // After this line add all other controlls you are adding...
     }
// Set up the cell...
cell.textLabel.text = @"foo";
return cell;
}
DShah
  • 9,768
  • 11
  • 71
  • 127
  • Which one you tried. I have given you 3 ways. Second option will definetly work. Are you using different images on Cell. Then you need to change it while SelectionStyle... – DShah Nov 10 '11 at 05:21