Using a XIB file for custom Tableview Section Header

后端 未结 3 1967
余生分开走
余生分开走 2021-02-15 15:33

I wanted to use a xib file to customise a tableview section in xcode (objective C), and here ar my files:

SectionHeaderView.xib is a UIView with a UILabel

Sectio

3条回答
  •  说谎
    说谎 (楼主)
    2021-02-15 15:51

    You can solve this issue by one of the following way:

    1) you have derived SectionHeaderView from UIView. derive this class with UIViewController instead. This will resolve your issue.

    2) Instead of using IBOutlet property, Set Tag of UILabel in view (say 101).

    Discard SectionHeaderview class.

    Keep SectionHeaderView.XIB, delete .m and .h files only.

    use following code ins Viewforheader method of MasterViewController class:

    {
        UIViewController *vc=[[UIViewController alloc] initWithNibName:@"SectionHeaderview" bundle:nil]
    
        UILable *lblTitle =[vc.view viewWithTag:101];
    
        lblTitle.text =@"Text you want to set";
    
        return vc.view;
    }
    

提交回复
热议问题