Ios 自定义UITableView单元格在UITableView中显示为空

Ios 自定义UITableView单元格在UITableView中显示为空,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我正在尝试动态创建一个自定义UITableViewCell,以便在分组的UITableView中显示。当自定义单元格在UITableView委托的tableView:CellForRowIndexAthPath方法中实例化时,表被放置在IB中的UIViewController中。问题在于加载视图控制器时,两个标签都不会出现在表视图中。UICountingLabel是一个自定义UILabel 我已经向tableView:registerClass注册了自定义实现。我将非常感谢任何帮助,并解释问题发

我正在尝试动态创建一个自定义UITableViewCell,以便在分组的UITableView中显示。当自定义单元格在UITableView委托的tableView:CellForRowIndexAthPath方法中实例化时,表被放置在IB中的UIViewController中。问题在于加载视图控制器时,两个标签都不会出现在表视图中。UICountingLabel是一个自定义UILabel

我已经向tableView:registerClass注册了自定义实现。我将非常感谢任何帮助,并解释问题发生的原因

/**
 * This is the custom cell for displaying
 * the data for the enemy cell at the 
 * game over screen
 * @df
 */
@implementation ADGameOverEnemyTableCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Create two labels, one for the name of the enemy and the
        // other for displaying the number of kills, adding the autolayout constraints
        bool isIphone = [[ADGameParameters sharedParameters] isIphone];

        self.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

        self.nameLabel = [[UILabel alloc] init];
        [self.nameLabel setTextColor:[UIColor whiteColor]];
        [self.nameLabel setFont:[UIFont fontWithName:@"Friday13" size:isIphone?15:20]];
        [self.contentView addSubview:self.nameLabel];

        self.killsLabel = [[UICountingLabel alloc] init];
        [self.killsLabel setFormat:@"%d"];
        [self.killsLabel setTextColor:[UIColor whiteColor]];
        [self.killsLabel setFont:[UIFont fontWithName:@"Friday13" size:isIphone?15:20]];
        [self.contentView addSubview:self.killsLabel];
    }
    return self;
}

- (void) layoutSubviews
{
    // Local pointer for the VFL
    UILabel *localNameLabel = self.nameLabel;
    UICountingLabel *localKillsLabel = self.killsLabel;

    // Layout contraints
    NSDictionary *views = NSDictionaryOfVariableBindings(localNameLabel, localKillsLabel); // Greatest macro ever!!!

    NSArray *verticalConstraintsForNameLabel =
    [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[localNameLabel]|" options:0 metrics:nil views:views];

    NSArray *verticalConstraintsForKillsLabel =
    [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[localKillsLabel]|" options:0 metrics:nil views:views];

    NSArray *horizontalConstraints =
    [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[localNameLabel]-[localKillsLabel]|" options:0 metrics:nil views:views];

    [self.contentView addConstraints:verticalConstraintsForNameLabel];
    [self.contentView addConstraints:verticalConstraintsForKillsLabel];
    [self.contentView addConstraints:horizontalConstraints];

    [super layoutSubviews];
}

@end
下面是tableView:forrowatinexpath的实现

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"Calling the cellForRowAtIndexPath");

    ADGameOverEnemyTableCell *cell = nil;
    // Query the arrays for the data
    switch ([indexPath section]) {
        case ADStatsEnemy:
        {
            cell = [tableView dequeueReusableCellWithIdentifier:enemyIdentifier];
            if (cell == nil)
            {
                cell = [[ADGameOverEnemyTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:enemyIdentifier];
            }

            [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; // Only the weapons cells are selectable
            NSLog(@"%@", indexPath);
            NSArray *keys = [enemyData allKeys];
            cell.nameLabel.text = [keys objectAtIndex:indexPath.row];
            NSDictionary *enemyDataDict = [enemyData objectForKey:[keys objectAtIndex:indexPath.row]];
            if ([enemyData isKindOfClass:[NSDictionary class]]){
                NSInteger val = [[enemyDataDict objectForKey:@"Killed"] integerValue];
//                cell.detailTextLabel.text = [NSString stringWithFormat:@"%d",val];
                [cell startKillsAnimationUpTo:val :4.0f];
            }
            else{
//                cell.detailTextLabel.text = @"NO DATA, CHECK self.enemyData integrity";
                cell.killsLabel.text = @"-1";
            }
        }
            return cell;
            break;

        default:
            break;
    }
    return nil;
}

你可以发布cellForRowAtIndexPath:请?我已经编辑了这个问题以包含方法实现,这里“AdStatsEnmy”包含哪些类型的内容?你可以在自定义单元格中设置标签的框架吗?@Chancy我刚刚提出了你的建议,单元格现在显示在表视图中。但是,这些约束不适用