繁体   English   中英

空的自定义原型单元

[英]Empty custom prototype cell

我是iPhone开发的新手,原型电池有问题。 在我的情节提要中,我有导航控制器。 我用视图控制器(作为主窗口)将其推入,它具有一个按钮,当我单击它时,将使用自定义原型单元打开tableView控制器

- (IBAction)searchClick:(id)sender {
CNCarTableController *car = [[CNCarTableController alloc]init];
[self.navigationController pushViewController:car animated:TRUE];

}

但是当它打开时它有空行

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:     ( NSIndexPath *)indexPath
 {
  static NSString *CellIdentifier = @"TransportCell";
  CNTransportCell *cell = [tableView       dequeueReusableCellWithIdentifier:CellIdentifier];

// Configure the cell...
if(cell == nil){
   cell = [[CNTransportCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
//cell.textLabel.text = @"bmv";

cell.name = (UILabel*) [cell viewWithTag:100];
[cell.name setText:@"a text"];
cell.number.text = @"number";
cell.car.text = @"car";
return cell;

}

但是如果要使用cell.textLabel.text = @"bmv"; 一切正常。 但是对于带有标签或cell.lbl.text的自定义单元格方式不起作用。 那里怎么了 带有View Controller的导航控制器可以带来细微差别吗?

自定义单元格代码:

  @interface CNTransportCell : UITableViewCell

  @property (nonatomic,weak) IBOutlet UILabel *name;
  @property (nonatomic,weak) IBOutlet UILabel *number;
  @property (nonatomic,weak) IBOutlet UILabel *car;

@结束

   @implementation CNTransportCell
   @synthesize name;
   @synthesize number;
   @synthesize car;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  {
   self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  if (self) {
    // Initialization code
  }
   return self;
 }
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
 {
   [super setSelected:selected animated:animated];

// Configure the view for the selected state
  }

@end

您在那里犯了小错误。 您的自定义单元格类是“ CNPlayerCell”,并且您正在从“ CNTransportCell”类分配新的单元格。

还有一件事,您是否已将自定义类分配给IB中的原型单元? (在身份检查器中)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM