开发者

Disclosure triangle is not appearing on my UITableViewCell

开发者 https://www.devze.com 2023-03-08 23:18 出处:网络
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:

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

精彩评论

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

关注公众号