In my iPhone app I have to show check-mark image on left side of the cell, first time there is no image on the cell, when user select the cell it will show the check mark image on right side of the cell, if user again select the same cell image should be hide.
Asked
Active
Viewed 1,189 times
3 Answers
1
First in your UITableView's Method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.accessoryType = UITableViewCellAccessoryCheckmark;
// Your code...
return cell;
}
and for show and hidden
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*) indexPath{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}else{
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
Hope this will help you.
All the best !!!

Yashesh
- 1,799
- 1
- 11
- 29
-
No. I have my cutom checkmark image and I have to show it in left side of the cell with same functionality as above code but only for the left side image Thankd – Nishi Mar 07 '13 at 07:46
-
1Its easy using above code. Just design your custom cell and it should have UIImageView which can show check mark. and instead of **cell.accessoryType** user **cell.imgCheckMark.image = yourImage** – Yashesh Mar 07 '13 at 08:30
-
1
if (cell.checkMarkImage.image == [UIImage imageNamed:@"checkMarkiPad.png"])
{
cell.checkMarkImage.image=[UIImage imageNamed:@""];
}
else{
cell.checkMarkImage.image = [UIImage imageNamed:@"checkMarkiPad.png"];
}

Nishi
- 683
- 1
- 12
- 31
0
You can use the accessorytype method of UITableViewcell,which can make you mark "checkmark" on the right side of the cell. And you have to use Custom button on the left side of the tableview,on which when user clicks,the chek and uncheck images should be changed.
in cellForRowAtIndex
method ->
{
// make a custom UIButton and set image on it.
UIButton *chk = [[UIButton alloc]initwithframe(0,0,30,30)];
[chk setBackgroundImage:[UIImage imagenamed:@"uncheck.png"]];
[chk addTarget:self action:@selector(YourbuttonAction:) forControlEvents:UIControlEventTouchUpInside]];
[cell addSubview:chk];
}
-(void)YourbuttonAction
{
// in this part ,you can change the buttons image on every click.
}
And if you still have problem,Have a look at following links ->
http://danielsaidi.wordpress.com/2012/08/14/checkable-uitableviewcell-with-custom-image/

Vineet Singh
- 4,009
- 1
- 28
- 39