在UItableview中选择如何检查单元格以进行图像显示 [英] How to check cell is selected in UItableview for image display
问题描述
我的应用程序是导航基础。我有UITableViewController。当我点击一个单元格时,我需要在所选单元格的左侧显示复选标记,以便选择单元格的指示。例如2个细胞。选择第一个单元格我需要指示单元格被选中用于复选标记。如果我选择第二个单元格我需要禁用第一个单元格复选标记,我需要在第二个单元格中显示复选标记。检查单元格选择。
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 selected 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 .
推荐答案
试试这个。在 cellForRowAtIndexPath 委托方法中输入以下代码。
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];
}
有一个名为 selectedRow 的整数变量,在你的 didSelectRowAtIndexPath 委托方法包括以下代码,
Have a integer variable named selectedRow and in your didSelectRowAtIndexPath delegate method include the following code,
...
selectedRow = indexPath.row;
[self.tableView reloadData];
确保初始化,
selectedRow = -1;
或在表格视图之前初始化的地方加载。
in init method or somewhere where it will be initialized before the table view loads.
这篇关于在UItableview中选择如何检查单元格以进行图像显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!