我提供了一个带有outlet属性的UITableViewCell子类MyCell (为了连接nib):
@interface MyCell : UITableViewCell
@property (nonatomic, strong) IBOutlet UILabel* theLabel;
@end然后我合成theLabel。然后,我想使用属性名来访问单元格:
MyCell *theCell = (MyCell *)cell;
UILabel *lab = theCell.theLabel;当我使用属性名访问单元格时,我收到一条错误消息:
[UITableViewCell theLabel]: unrecognized selector
我好像漏掉了什么。为什么会抛出异常?
发布于 2012-12-20 05:16:35
您的问题是,在cellForRowAtIndexPath函数中,您没有正确地将单元格实例化为"MyCell“类型,而只是试图将指针静态转换为指向它的指针。最后,您尝试访问一个在普通UITableViewCell中不存在的属性。
您加载的单元格是否与此类似?:
static NSString *reuseIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:self options:nil] objectAtIndex:0];
}https://stackoverflow.com/questions/13961245
复制相似问题