UITableViewCell内容未显示

时间:2014-12-18 13:57:58

标签: ios objective-c xcode uitableview

我有委托方法来检索每个单元格的内容,如下所示:

-(void)getRetrievedShopContentStickerName:(NSArray *)stickerNameArray price:(NSArray *)stickerPriceArray profileBackgroundImage:(NSArray *)stickerProfileBackgroundImageArray profile:(NSArray *)stickerProfileImageArray profileMenuImage:(NSArray *)stickerProfileMenuImageArray designerName:(NSArray *)designerNameArray
{
    self.stickerPriceArray = [[NSMutableArray alloc] initWithArray:stickerPriceArray];
    self.stickerProfileBGImageArray = [[NSMutableArray alloc] initWithArray:stickerProfileBackgroundImageArray];

    NSLog(@"sticker price: %@", self.stickerPriceArray);
    NSLog(@"sticker bg: %@", self.stickerProfileBGImageArray);

    [self.shopTableView reloadData];
}

此委托方法按预期注销一个正在运行的数组。这是我用于显示表格视图内容的代码:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.stickerPriceArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

        AsyncImageView *backgroundImage = [[AsyncImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)]; //does cell frame get before this method?
        [backgroundImage setTag:123];
        [cell.contentView addSubview:backgroundImage];

        UILabel *priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 250, 250)];
        [priceLabel setTag:124];
        [priceLabel setFont:[UIFont fontWithName:@"Helvetica-Light" size:30.0f]];
        [priceLabel setTextColor:[UIColor blackColor]];
        [cell.contentView addSubview:priceLabel];
    }

    [(AsyncImageView *)[cell.contentView viewWithTag:123] loadImageWithTypeFromURL:[NSURL URLWithString:[self.stickerProfileBGImageArray objectAtIndex:indexPath.row]] contentMode:UIViewContentModeScaleAspectFit imageNameBG:nil];
    [(UILabel *)[cell.contentView viewWithTag:124] setText:[self.stickerPriceArray objectAtIndex:indexPath.row]];

    return cell;
}

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

在委托方法中重新加载表视图后,我得到的唯一更改是每个tableviewcell的高度。为什么我的内容没有显示?我做错了什么?

提前致谢

1 个答案:

答案 0 :(得分:0)

我不小心在故事板中设置了我的单元格标识符,因此从未调用if (cell == nil)