Fix Talbleview the head or bottom child controls do not display problems

Source: Internet
Author: User

When you customize the cell header control Uitableviewheaderfooterview (almost the same way as a custom cell), there is an issue where the head control child controls do not appear.

Note the difference from the custom cell.

. h file

1 #import<UIKit/UIKit.h>2 #import "CHModleGroup.h"3 @interfaceHeaderview:uitableviewheaderfooterview4@property (nonatomic, weak) UILabel *count;5@property (nonatomic, weak) UIButton *name;6+ (Instancetype) Headerviewwithtableview: (UITableView *) TableView;7 8@property (nonatomic, strong) Chmodlegroup *Group;9 Ten @end

. m file

1 #import "HeaderView.h"2 3 @implementationHeaderview4+ (Instancetype) Headerviewwithtableview: (UITableView *) tableview{5     StaticNSString *id =@"Header";6Headerview *header =[TableView Dequeuereusableheaderfooterviewwithidentifier:id];7     if(Header = =Nil) {8Header =[[Headerview alloc]initwithreuseidentifier:id];9     }Ten     returnheader; One } A  -- (ID) Initwithreuseidentifier: (NSString *) Reuseidentifier - { the     if(self =[Super Initwithreuseidentifier:reuseidentifier]) { -UIButton *nameview =[UIButton Buttonwithtype:uibuttontypecustom]; -         //Background Image -[Nameview setbackgroundimage:[uiimage imagenamed:@"Publish a copy of the news background"] forstate:uicontrolstatenormal]; +[Nameview setbackgroundimage:[uiimage imagenamed:@"Welcome3"] forstate:uicontrolstatehighlighted]; -         //set the left arrow image inside the button +[Nameview setimage:[uiimage imagenamed:@"buddy_header_arrow Copy"] forstate:uicontrolstatenormal]; A [Nameview Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstatenormal]; at         //set the contents of the button to align left -Nameview.contenthorizontalalignment =Uicontrolcontenthorizontalalignmentleft; -         //set the inner margin of a button -         //nameview.imageedgeinsets -Nameview.titleedgeinsets = Uiedgeinsetsmake (0,Ten,0,0); -Nameview.contentedgeinsets = Uiedgeinsetsmake (0,Ten,0,0); in [Self.contentview Addsubview:nameview]; -Self.nameview =Nameview; to          +          -          the         //2. Add the number of friends *UILabel *countview =[[UILabel alloc] init]; $Countview.textalignment =Nstextalignmentright;Panax NotoginsengCountview.textcolor =[Uicolor Graycolor]; - [Self.contentview Addsubview:countview]; theSelf.countview =Countview; +          A  the     } +         returnSelf ; -     } $  $ /** - * When a frame of a control changes, it is called -  * the * Typically here the child controls inside the layout (set the child control's frame) -  */Wuyi- (void) Layoutsubviews the { -     //Be sure to call the Super method Wu [Super Layoutsubviews]; -      About     //1. Set the frame of the button $Self.nameView.frame =self.bounds; -      -     //2. Set the number of frame -CGFloat County =0; ACGFloat Counth =Self.frame.size.height; +CGFloat COUNTW = Max; theCGFloat Countx = self.frame.size.width-Ten-COUNTW; -Self.countView.frame =CGRectMake (Countx, county, COUNTW, counth); $ } the  the //Setting up data the- (void) Setgroup: (Mjfriendgroup *) Group the { -_group =Group; in      the     //1. Set the button text (group name) the [Self.name setTitle:group.name forstate:uicontrolstatenormal]; About      the     //2. Set Quantity (total) theSelf.count.text = [NSString stringWithFormat:@"%lu", Friends.count]; the } +  -  the @end

Fix Talbleview the head or bottom child controls do not display problems

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.