xcode 如何检查在UItableview中选择单元格进行图像显示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4453413/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:01:08  来源:igfitidea点击:

How to check cell is selected in UItableview for image display

iphoneobjective-ciosxcodeuitableview

提问by SOF

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 .

我的应用程序是导航基础。我有 UITableViewController.当我点击一个单元格时,我需要在所选单元格的左侧显示复选标记以指示单元格被选中。例如 2 个单元格。选择了第一个单元格,我需要指示为复选标记选择了单元格。如果我选择第二个单元格,我需要禁用第一个单元格复选标记,我需要在第二个单元格中显示复选标记。如何检查单元格选择。

回答by EmptyStack

Try this. In your cellForRowAtIndexPathdelegate method put the following code.

尝试这个。在您的cellForRowAtIndexPath委托方法中放置以下代码。

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 selectedRowand in your didSelectRowAtIndexPathdelegate method include the following code,

有一个名为selectedRow的整数变量,并在您的didSelectRowAtIndexPath委托方法中包含以下代码,

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

Make sure you initialize ,

确保你初始化,

selectedRow = -1;

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

init方法中或在表视图加载之前将被初始化的某个地方。

回答by fabian789

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

你可能想看看这里。或者只是谷歌的附件视图,这就是你必须设置的。