简体   繁体   中英

Empty custom prototype cell

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];

}

But when it opens it has empty rows

 - (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;

}

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?

Custom cell code:

  @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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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