0

我在访问数组中的对象时遇到问题。我将“放置”对象存储在我的 NSMutableArray 中。我想为我的 TableView 访问这个数组。我在第一行收到“没有已知的选择器实例方法”错误。请参阅下面的行。

cell.imageView = [[self.currentPlaces objectAtIndex:indexPath.row]picture];
cell.subtitleLB.text = [[self.currentPlaces objectAtIndex:indexPath.row]description];
cell.objectNameLB.text = [[self.currentPlaces objectAtIndex:indexPath.row]name];

这是我的地方对象:

@interface Place : NSObject{

CLLocation *objectLocation;
UIImageView *picture;
NSString *name;
NSString *description;
}

属性“描述”和“名称”的访问没有问题。我只是不知道为什么会发生这个错误。

谢谢。多米尼克

4

2 回答 2

2

我有同样的问题; 对我有用的是传递 UIImage 而不是 UIImageView。所以你的代码应该是这样的:

@interface Place : NSObject{

CLLocation *objectLocation;
UIImage *picture;
NSString *name;
NSString *description;
}

和这个

cell.imageView.image = [[self.currentPlaces objectAtIndex:indexPath.row]picture];
cell.subtitleLB.text = [[self.currentPlaces objectAtIndex:indexPath.row]description];
cell.objectNameLB.text = [[self.currentPlaces objectAtIndex:indexPath.row]name];

如果这不起作用,我会发布更多代码供您查看。

于 2012-07-02T19:28:49.810 回答
2

您实际上还没有声明任何方法。您声明的是实例变量。您可能应该使用@propertys 代替。

@interface Place : NSObject
@property (nonatomic, retain) CLLocation *objectLocation;
@property (nonatomic, retain) UIImageView *picture;
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy, getter=objectDescription) NSString *description;
@end

这实际上将创建您想要的方法。请注意,我将description属性的方法更改为 read -objectDescription。这是因为NSObject已经声明了该-description方法,并且您不应该用不相关的属性覆盖它。

如果您使用最近的 Clang,那么这就是您所需要的,并且实例变量将自动合成(使用下划线前缀,例如_picture)。如果您使用的是旧版本(例如,如果这会导致错误),则需要添加@synthesize行,如

@implementation Place
@synthesize objectLocation=_objectLocation;
@synthesize picture=_picture;
@synthesize name=_name;
@synthesize description=_description;
@end
于 2012-07-02T19:38:37.223 回答