我有继承的UITableViewCell A类(自定义表单元格)。它有成员表示X是一个UILabel。

现在,如果我想设置像a.x.text cellForRowAtIndexPath方法中=“一些文本”值,我正在编译器错误“的错误在细胞成员x,其是非类类型的UITableViewCell的”。

能否请你让我知道我怎么能解决这个问题?

感谢。

有帮助吗?

解决方案

首先,确保你的财产是正确定义:

@interface A : UITableViewCell {
  UILabel *x;
}

@property (nonatomic, retain) IBOutlet UILabel *x;

@end

然后确保你已经在你的表视图的数据源包括A.H,并确保你铸造单元格中键入答:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  static NSString *cellIdentifier = @"cell";
  A *a = (A *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  if (a == nil) {
    a = [[A alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier];
  }
  a.x.text = @"some text";
  return a;
}

其他提示

一定要添加x作为属性子类:

@interface ACell : UITableViewCell {
      UILabel *X;
}

@property (readonly, nonatomic) UILabel* X;

尝试使用:

[[a x] setText:@"your text];

和看看会发生什么。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top