我正在使用以下代码初始化UITableView中的文本标签:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *CellIdentifier = [menuItems objectAtIndex:indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    [cell.textLabel setText: [menuTitlesEN objectAtIndex:indexPath.row]];
    return cell;
}

我的表由四个静态单元格组成,每个单元格包含一个UIImageView和一个UILabel。

当不调用setText时,我的表应如下所示:

但是调用setText会导致UIImage消失:

我是iOS开发的新手。谁能指导我正确的方向?

最佳答案

由于您要覆盖默认单元格的UILabel(cell.textLabel)。因此,最好将标记属性赋予UILabel中的自定义UITableViewCell,然后为其分配文本。

尝试类似:

UILabel *lbl = (UILabel*)[cell viewWithTag:identityOfUILabel];
[lbl setText: [menuTitlesEN objectAtIndex:indexPath.row]];

关于ios - 尝试设置UILabel的文本时,UIImage消失,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24709569/

10-13 04:05
查看更多