开发者

How to check cell is selected in UItableview for image display

开发者 https://www.devze.com 2023-01-31 06:42 出处:网络
My application is navigation base. I haveUITableViewController.when i tap a cell i need to display check mark in left side of selected cell forindication of cell is selected. For example 2 cell . Firs

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 selected. For example 2 cell . First cell is sel开发者_StackOverflow中文版ected i need to indicate cell is selected for check mark. if i select second cell i need to disable first cell check mark and i need to show check mark in second cell.how to check cell selection .


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消