Вопрос

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.

Это было полезно?

Решение 2

 if (cell.checkMarkImage.image == [UIImage imageNamed:@"checkMarkiPad.png"])
{
    cell.checkMarkImage.image=[UIImage imageNamed:@""];
}
else{
    cell.checkMarkImage.image = [UIImage imageNamed:@"checkMarkiPad.png"];
}

Другие советы

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 !!!

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/

http://pastebin.com/L99v2jBQ

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top