Custom UITableViewCell with Subtitle style

后端 未结 2 1926
别跟我提以往
别跟我提以往 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:34

    Use Option B. Either fully use your own custom cell, or fully use Apple's styled cell. Trying to mix and match is not forward compatible.

    If you want a convenient property for the detailTextLabel, subclass UITableViewCell and return the UILabel you create in the nib. Give it a different name than detailTextLabel.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题