iOS: пользовательский UITableViewCell не показывает данные
Я создал UITableView
внутри моего UIViewController
и я построил прототип ячейки в раскадровке. Я назначил теги для всех элементов в ячейке, которую я хочу изменить, и я изменяю их в коде.
Когда (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
вызывается, мои данные обрабатываются, и я вижу, как появляется ячейка с красным цветом фона, который я установил в раскадровке, однако изображения или текст отсутствуют. Я думаю, что проблема с реализацией, но я не могу понять, что я делаю неправильно.
Вот как выглядит раскадровка:
Это соответствующий код:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
if(tableView == youLikeTableView)
{
UIView* youLikeImageFrame = (UIView *)[cell.contentView viewWithTag:100];
UIImageView* youLikeImageView = (UIImageView *)[cell.contentView viewWithTag:101];
UILabel *youLikeNameLabel = (UILabel *)[cell.contentView viewWithTag:102];
for(int i = 0; i < [youLike count]; i++)
{
youLikeImageFrame.layer.cornerRadius = youLikeImageFrame.frame.size.width / 2;
[youLikeImageView setImage:[youLikeImages objectAtIndex:i]];
youLikeImageView.layer.cornerRadius = youLikeImageView.frame.size.width / 2;
youLikeNameLabel.text = [youLikeName objectAtIndex:i];
}
}
return cell;
}
И эта ячейка появляется без текста или изображений
1 ответ
Решение
you forgot to add them as subview
[cell addSubView:youLikeImageFrame];
[cell addSubView: youLikeImageView]; and
[cell addSubView: youLikeNameLabel];
как раз перед
return cell;