无法访问uitableviewcell中的属性

时间:2015-03-28 15:41:14

标签: ios uitableview properties

我有一些自定义的tableviewcells,每个都有一个带有手势识别器的缩略图,用于打开一个模态框。

在每个tableviewcell中都有一个包含字符串的属性。

在手势识别器调用的方法中,我试图通过循环手势识别器的超视图来访问此属性。

 - (void)handleLongPress:(UILongPressGestureRecognizer *)LongPressGestureRecognizer
 {
    //handle press
    ZoomImageViewController *zoomImage = [self.storyboard instantiateViewControllerWithIdentifier:@"zoomImage"];

    UIView *subview = LongPressGestureRecognizer.view;
    while (![subview isKindOfClass:[UITableViewCell self]] && subview) {
        subview = subview.superview;
    }

    UITableViewCell *cell = (UITableViewCell *)subview;

    zoomImage.filename = cell.machinePicture;
    zoomImage.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

    [self presentViewController:zoomImage animated:YES completion:nil];

}

在调试器中,单元格对象是包含我想要访问的属性的tableviewcellcontroller。 但是,在接下来的行中,我得到错误“属性'机器图片''找不到'UITableViewCell *'类型的对象”

zoomImage.filename = cell.machinePicture;

我不明白为什么财产无法找到,而细胞似乎是我正在寻找的正确对象,包含我想要的属性......

2 个答案:

答案 0 :(得分:0)

标准UITableViewCell不包含machinePicture属性,您是否扩展了UITableViewCell类?

使用该自定义类,相应地进行转换:

MyUITableViewCell *cell = (MyUITableViewCell *)subview;

答案 1 :(得分:0)

UITableviewCell你不会获得一个属性machinePicture,因为它不是UITableViewCell中的属性。我认为您正在使用自定义表格视图单元格。所以你必须对它进行类型转换。其次,您必须使用tableview:didSelectRowAtIndexPath: UITableViewDelegate方法获取tableviewcell而不使用手势识别器。