2011-05-27 61 views
0

我怎样才能在UITableViewCell上有一个标签,但在它的右侧还有一个箭头?披露三角没有出现在我的UITableViewCell上

这是我的尝试:

} else if(indexPath.row == 1) { 
     UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50,0,200,21)]; 
     label.text = @"Select to change code"; 
     label.tag = 1; 
     label.textColor = [UIColor grayColor]; 
     cell.accessoryView = label; 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 

但它不工作。我看到标签,但没有看到电池右侧的箭头。

+0

我想告诉你,你的问题的标题可能是不正确的...... – DreamOfMirrors 2011-05-27 11:56:40

+0

@DreamOfMirrors - 不再事实并非如此。 – Abizern 2011-05-27 11:57:33

回答

3

尝试以下操作:

else if(indexPath.row == 1) { 
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50,0,200,21)]; 
    label.text = @"Select to change code"; 
    label.tag = 1; 
    label.textColor = [UIColor grayColor]; 
    [cell addSubview:label];//i changed oonly this line 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
} 

希望它可以帮助你........

编辑:(因为我不能评论的原因小的变化是在原始代码你已经将标签添加到单元格中,因为它的accessoryType子视图(有效地用你的标签覆盖它),而在修改后的代码中,标签被正确添加为单元格的单独子视图

+0

这应该是[cell.contentView addSubview] - 不要直接添加东西到单元格。此外,如果使用默认标题和/或图像视图,它将简单地重叠。 – 2011-05-27 12:42:51

0

你不能同时拥有自定义配件视图和系统提供的视图你得到cell.accessoryType。这个怎么样:

cell.textLabel.text = @"Select to change code"; 
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;