UITableViewCell Content Not Displaying

I have a delegation method that retrieves the content for each cell as follows:

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

These delegate methods exit the working array as expected. This is the code I used to display the contents of a table view:

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

The only change I get after reloading the table view in the delegate method is the height of each tableviewcell. Why is my content not showing? What have I done wrong?

Thanks in advance

+4
source share
1 answer

I accidentally set my cell id in the storyboard so it if (cell == nil)would never be called.

0
source

Source: https://habr.com/ru/post/1568161/


All Articles