为什么我不能从 NSArray 返回的自定义对象调用 public 方法?

why cant i invoke public method from a custom object returned from NSArray?

所以我正在做的是在调用 tableView:cellForRowAtIndexPath: 时尝试获取索引 i 处的数组的值。当我调试它时,我实际上将我的对象视为我的自定义对象,但我无法访问它的方法。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    // some code to get the cell here   

    id dilemaView = self.dataArray[indexPath.row];
    DilemaUIView * dv = (DilemaUIView *)dilemaView;

    if([dilemaView isKindOfClass:[DilemaUIView class]]){
        cell.imageView.image = [dilemaView getLeftImage];
    }

    return cell;
}

问题是 isKindOfClass 总是 returns 不。我哪里错了?谢谢!

请尝试检查 dv 而不是 dilemaview

if([dv isKindOfClass:[DilemaUIView class]]){
        cell.imageView.image = [dilemaView getLeftImage];
    }

感谢你们的帮助。我想我发现了问题 - 当我创建从 UIView 继承的 DilemaUIView 时,我这样设置自己:

self = (DilemaUIView*)imageView;

其中 imageView 是 UIImageView 类型。这就是为什么我不能把它放回原处。 实际上,现在它更简单了,因为我想从中获取图像,现在我可以使用

cell.imageView.image = dv.image;

非常感谢!