空自定义原型单元格 [英] Empty custom prototype cell

查看:93
本文介绍了空自定义原型单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iPhone开发的新手,并且原型单元存在问题。
在我的故事板中,我有导航控制器。我用视图控制器推送它(作为主窗口),它有一个按钮,当我点击它时我打开带有自定义原型单元格的tableView控制器

I'm new in iPhone development and have problem with prototype cell. In my storyboard, I have navigation controller. I pushed it with view controller (as main window), it has a button, when I click it I open tableView controller with custom prototype cell

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

But if will use cell.textLabel.text = @"bmv"; all works ok. But for custom cell way with tags or cell.lbl.text don't work. What is wrong there? Can it be a nuance of navigation controller with view controller?

自定义单元代码:

  @interface CNTransportCell : UITableViewCell

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

@end

   @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类中分配新单元格。

you have done small mistake there. Your custom cell class is "CNPlayerCell" & you are allocating new cells from "CNTransportCell" class.

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

One more thing, have you assigned custom class to your prototype cell in IB? (In identity inspector)

这篇关于空自定义原型单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆