我有一个带有自定义单元格的UITableView,该单元格包含UIImageView和UILabel。现在,当我第一次加载我的表格时,它会在每个单元格上加载相同的图像和不同的标签,这些标签来自LabelArray。
现在,我说的图像是一个radioButton,因此,当用户点击单元格时,图像会改变。如果用户再次点击,则将其更改为默认状态。
为了实现这一点,我使用了这个函数,并在我的customcell类中声明了一个名为selectionStatus的布尔变量。
这样做没问题,但我想知道是否这是一种正确的方式,或者我们可以检查cell.selected属性。我能够得到所需的效果。但现在,当我关闭视图并再次打开它时,该函数...
现在,我说的图像是一个radioButton,因此,当用户点击单元格时,图像会改变。如果用户再次点击,则将其更改为默认状态。
为了实现这一点,我使用了这个函数,并在我的customcell类中声明了一个名为selectionStatus的布尔变量。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell * cell = (CustomCell* )[tableView cellForRowAtIndexPath:indexPath];
if(indexPath.row == 0)
{
if(cell.selectionStatus == TRUE)
{
//Do your stuff
cell.selectionStatus = FALSE;
}
else
{
//Do your stuff
cell.selectionStatus = TRUE;
}
}
if(indexPath.row == 1)
{
if(cell.selectionStatus == TRUE)
{
//Do your stuff
cell.selectionStatus = FALSE;
}
else
{
//Do your stuff
cell.selectionStatus = TRUE;
}
}
}
这样做没问题,但我想知道是否这是一种正确的方式,或者我们可以检查cell.selected属性。我能够得到所需的效果。但现在,当我关闭视图并再次打开它时,该函数...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if([self.checkedIndexpath count] == 0)
{
[tableCell.selectionImage setImage:@"xyz.png"];
}
else
{
for (int i =0; i <[self.checkedIndexPath count]; i++)
{
NSIndexPath *path = [self.checkedIndexPath objectAtIndex:i];
if ([path isEqual:indexPath])
{
[tableCell.selectionImage setImage:@"abc.png"]
}
else
{
[tableCell.selectionImage setImage:@"xyz.png"]
}
}
return tableCell;
问候 Ranjit