[英]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.