【问题标题】:Empty custom prototype cell空的自定义原型单元格
【发布时间】:2014-01-17 02:46:49
【问题描述】:

我是 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 的自定义单元格方式不起作用。那里有什么问题?它可以是带有视图控制器的导航控制器的细微差别吗?

自定义单元格代码:

  @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

【问题讨论】:

  • 您是如何制作自定义单元格的?
  • @amar 我贴的是custum cell的代码,Indentifier是TransportCell

标签: ios iphone ios5 storyboard


【解决方案1】:

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

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

【讨论】:

  • yes :) 对不起,我复制了其他类,但 CNTransportCell 是一样的,其他地方有问题。
  • 您是否在身份检查器中为原型单元分配了自定义类?接下来,检查“区分大小写”的单元格标识符。是一样的吗?让我知道。你能用正确的类更新你的代码吗?
  • 是的,我做了这些事情,是的,它们是一样的。我已经更新了它,我也尝试使用这个 arcticle 以编程方式创建 custum 单元,它可以工作danielhanly.com/blog/tutorial/…,但是当我使用原型单元时它不起作用。
猜你喜欢
  • 1970-01-01
  • 2012-08-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-28
  • 1970-01-01
  • 1970-01-01
  • 2019-06-14
相关资源
最近更新 更多