0

I am showing a image in CellImage when any cell is clicked it works fine but problem is that when a new cell is selected then previous cell image is also visible i want that when user selects on new cell previous cellImage should be hidden.

这是代码

-(IBAction)imageButtonAction:(id)sender{

CustomCell *cell = (CustomCell *) [[sender superview] superview];
UIButton *btn = (UIButton *)sender;
UIView *backimage = [[UIView alloc] initWithFrame:CGRectMake(300,0,312,105)];
backimage.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"popupj.png"]];
[backimage setUserInteractionEnabled:YES];
[cell addSubview:backimage];
}

我在使用自定义单元格的单元格中的按钮上调用此方法

这是图像的屏幕截图

4

4 回答 4

0

There is a value on a table view xib called selection, check that its value is set to single selection in your xib. Or programmatically set this property to NO:

@property(nonatomic) BOOL allowsMultipleSelection
于 2013-07-09T06:25:02.033 回答
0

在您的按钮操作中,您可以设置维护应在 .h 文件中声明的previousIndexPath 。通过使用此 previousIndexPath,您可以轻松隐藏先前加载的图像:

      CustomCell *cell=(CustomCell *)[yourTable cellForRowAtIndexPath:previousIndexPath];
      cell.yourImage.hidden=TRUE;
于 2013-07-09T06:30:58.803 回答
0

更改 tableView:didSelectRowAtIndexPath 中先前选定单元格的隐藏值属性:使用以下命令访问单元格:

UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:previousIndex];
cell.yourImage.hidden = YES;
于 2013-07-09T06:35:02.230 回答
0

你可以试试这个,它可能对你有帮助。

-(IBAction)imageButtonAction:(id)sender{

    CustomCell *cell = (CustomCell *) [[sender superview] superview];
    UIButton *btn = (UIButton *)sender;
    for (UIView *subView in cell.contentView.subviews) {
        if([subView isKindOfClass:[UIView class]]){
            subView.hidden=YES;
        }
    }
    UIView *backimage = [[UIView alloc] initWithFrame:CGRectMake(300,0,312,105)];
    backimage.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"popupj.png"]];
    [backimage setUserInteractionEnabled:YES];
    [cell addSubview:backimage];
}

或者你甚至可以使用块来循环子视图并隐藏它们

干杯

于 2013-07-09T06:36:11.420 回答