Отображение пользовательской ячейки в UITable - PullRequest
1 голос
/ 16 декабря 2010

Я пытаюсь отобразить мои данные, которые находятся в UITableView, в пользовательских ячейках, которые я создал.Это мой пользовательский класс ячеек (CustomCell.m):

@implementation CustomCell

@synthesize primaryLabel, secondaryLabel, myImageView;

- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
   if (self == [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
     // Initialization code
     primaryLabel = [[UILabel alloc]init];
     primaryLabel.textAlignment = UITextAlignmentLeft;
     primaryLabel.font = [UIFont systemFontOfSize:14];
     secondaryLabel = [[UILabel alloc]init];
     secondaryLabel.textAlignment = UITextAlignmentLeft;
     secondaryLabel.font = [UIFont systemFontOfSize:8];
     myImageView = [[UIImageView alloc]init];
     [self.contentView addSubview:primaryLabel];
     [self.contentView addSubview:secondaryLabel];
     [self.contentView addSubview:myImageView]; 
    }
    return self;
  }

- (void)layoutSubviews {
    [super layoutSubviews];
    CGRect contentRect = self.contentView.bounds;
    CGFloat boundsX = contentRect.origin.x;
    CGRect frame;
    frame= CGRectMake(boundsX+10 ,0, 50, 50);
    myImageView.frame = frame;
    frame= CGRectMake(boundsX+70 ,5, 200, 25);
    primaryLabel.frame = frame;
    frame= CGRectMake(boundsX+70 ,30, 100, 15);
    secondaryLabel.frame = frame;
  }

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}

Затем я создал rootViewController с таблицей, в которой должны отображаться пользовательские ячейки (TeamsViewController.m):

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{
// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
// Return the number of rows in the section.
    return 5;
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{    
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}


// Custom cell here
    switch (indexPath.row) {
     case 0:
      cell.primaryLabel.text =@"Meeting on iPhone Development";
      cell.secondaryLabel.text = @"Sat 10:30";
      cell.myImageView.image = [UIImage imageNamed:@"Icon4.png"];
      break;
     case 1:
      cell.primaryLabel.text = @"Call With Client";
      cell.secondaryLabel.text = @"Planned";
      cell.myImageView.image = [UIImage imageNamed:@"Icon4.png.png"];
      break;
     case 2:
      cell.primaryLabel.text = @"Appointment with Joey";
      cell.secondaryLabel.text = @"2 Hours";
      cell.myImageView.image = [UIImage imageNamed:@"Icon4.png.png"];
      break;
     case 3:
      cell.primaryLabel.text = @"Call With Client";
      cell.secondaryLabel.text = @"Planned";
      cell.myImageView.image = [UIImage imageNamed:@"Icon4.png.png"];
      break;
     case 4:
      cell.primaryLabel.text = @"Appointment with Joey";
      cell.secondaryLabel.text = @"2 Hours";
      cell.myImageView.image = [UIImage imageNamed:@"Icon4.png.png"];
      break;
     default:
      break;
    }

return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
// Navigation logic may go here. Create and push another view controller.
    [self.navigationController pushViewController:self.teamsView animated:YES];
}

Итак, проблема: данные не отображаются в ячейках, и я не понимаю, почему.Вот снимок экрана того, как это в настоящее время выглядит.

http://dl.dropbox.com/u/1481176/Screen%20shot%202010-12-16%20at%203.30.42%20PM.png

Любая помощь будет принята с благодарностью!Спасибо.

1 Ответ

2 голосов
/ 16 декабря 2010

Вы звоните initWithStyle:reuseIdentifier: вместо вашего перезаписанного initWithFrame:reuseIdentifier:

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...