2

I want to create a check mark in the table view. When I tap the particular row, the check mark is visible, so I want to display the check mark when selected at the particular row. Please guide me and give me some links.

Here my code is,

  - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

                [self.tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
          }

I want to display the accessory type, when I click the particular state(selected only one row at a time).

Thanks.

Moshe
  • 57,511
  • 78
  • 272
  • 425
Pugalmuni
  • 9,350
  • 8
  • 56
  • 97
  • Gosh 6000+ views without actual answer??! – Stas Mar 31 '13 at 19:29
  • http://stackoverflow.com/questions/12814060/check-uncheck-buttons-in-uitableviews-cell/12814962#12814962 – TheTiger Aug 04 '13 at 08:17
  • 1
    This is covered in the accepted answer for http://stackoverflow.com/questions/5959950/iphone-uitableview-cellaccessory-checkmark -- in fact this question is a duplicate of that one. – idz Aug 06 '13 at 17:59

2 Answers2

1

Make sure you delegate is set properly for this controller and that the table view is connected to the delegate on the controller:

tableview.delegate = self;

After that your code should work. I tried your code in my own app and it worked (minus the self.tableview, since my tableview is not a property of the controller.)

Jbryson
  • 2,875
  • 1
  • 31
  • 53
-2

So you can do this by showing an image of check mark in your row.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{

    int x = tableView.frame.size.width - 20; //or whatever x coordinate
    int y = [self.tableView cellForRowAtIndexPath:indexPath].frame.size.height - 10;
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, 20, 20)];
    imgView.image = [UIImage imageNamed:@"image.png"];
    [self.tableView cellForRowAtIndexPath:indexPath] addSubview:imgView];
}
timgcarlson
  • 3,017
  • 25
  • 52
Vish
  • 341
  • 1
  • 4
  • 19
  • You are reinventing the wheel, IOS already has the desired feature with cell.accessoryType = UITableViewCellAccessoryCheckmark – Pedro Borges Aug 28 '14 at 16:02