How to check cell is selected in UItableview for image display

后端 未结 2 1378
别那么骄傲
别那么骄傲 2021-01-01 08:40

My application is navigation base. I have UITableViewController.when i tap a cell i need to display check mark in left side of selected cell for indication of cell is sele

相关标签:
2条回答
  • 2021-01-01 08:53

    You might want to look here. Or just google for accessoryView, that's what you have to set.

    0 讨论(0)
  • 2021-01-01 09:00

    Try this. In your cellForRowAtIndexPath delegate method put the following code.

    if (cell == nil) {
        ...
        [[cell imageView] setImage:[UIImage imageNamed:@"checkMark"]];
        ... 
    }
    
    [[cell imageView] setHidden:YES];
    
    if (indexPath.row == selectedRow) { 
        [[cell imageView] setHidden:NO];
    }
    

    Have a integer variable named selectedRow and in your didSelectRowAtIndexPath delegate method include the following code,

    ...
    selectedRow = indexPath.row;
    [self.tableView reloadData];
    

    Make sure you initialize ,

    selectedRow = -1;
    

    in init method or somewhere where it will be initialized before the table view loads.

    0 讨论(0)
提交回复
热议问题