开发者

Disclosure triangle is not appearing on my UITableViewCell

How can I have a label on a UITableViewCell but also have an arrow on the very right side of it?

This is what I tried:

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

But it's not working. I s开发者_JAVA百科ee the label but I do not see the arrow on the very right side of the cell.


Try the following :

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

Hope it helps you........

Edit: (because I can not comment. The reason for the small change is in your original code you had added the label to the cell as it's accessoryType subView (effectively covering it with your label) whereas in the revised code, the label was correctly added as a separate subview to the cell.


You can't have both a custom accessory view and the system supplied view that you get with cell.accessoryType. How about this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜