Custom UITableViewCell with Subtitle style

后端 未结 2 1927
别跟我提以往
别跟我提以往 2021-02-18 16:03

I used this guide: http://www.bdunagan.com/2009/06/28/custom-uitableviewcell-from-a-xib-in-interface-builder to be able to create my own custom UITableViewCell with a nice backg

2条回答
  •  天涯浪人
    2021-02-18 16:50

    If you want to use detailTextLabel in a custom button, follow these steps:

    1. Override UITableViewCell

    // MYTableViewCell.h:
    @interface MYTableViewCell : UITableViewCell
    @end
    

    2. Add a new IBOutlet to your subclass

    // MYTableViewCell.m
    @interface MYTableViewCell ()
    
    @property (nonatomic, weak) IBOutlet UILabel* detailLabel;
    
    @end
    

    3. Override -detailTextLabel

    @implementation MYTableViewCell
    
    - (UILabel*)detailTextLabel
    {
        return self.detailLabel;
    }
    
    @end
    

    4. Set up interface builder

    Set the custom class for your tableview cell to be MYTableViewCell and associate your UILabel with your new IBOutlet. Future calls to detailTextView on your tableview cell will now correctly return the proper text view. In this way, you can mix custom and OS provided tableview cells without worrying about the detailTextView.

提交回复
热议问题