uitableview子视图:为什么这个uilabel不可见? [英] uitableview subview : why this uilabel is not visible?

查看:121
本文介绍了uitableview子视图:为什么这个uilabel不可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在tableview的每个单元格中显示一个显示数字的标签,但只有当我点击一行时(当单元格高位时)才能看到标签

I want to display a label showing a number in each cell of the tableview but the label is only visible when I click on a row (when the cell is highlited)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UILabel *label;
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        label = [[UILabel alloc] initWithFrame:CGRectMake(200,10, 15, 15)];
        label.tag = 1;
        [cell.contentView addSubview:label];
        [label release];
    }
    else {
        label = (UILabel *)[cell viewWithTag:1];   
    }
    if (indexPath.row == 0) {
        cell.textLabel.text = @"Photos";
        label.text = [NSString stringWithFormat:@"%d",1];
    }
    return cell;
}


推荐答案

我遇到了同样的问题,它是通过在将自定义标签添加为子视图之前设置textlabel的文本来解决的。

I had the same problem and it was solved by setting the text for textlabel BEFORE adding the custom label as a subview.

...
cell.textLabel.text = @"X";
...
[cell.contentView addSubview:label]

这篇关于uitableview子视图:为什么这个uilabel不可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆