ios - Spacing between UITableview header and top cell -


i'm getting odd behavior uitableview.

there's spacing between uitableview header , first cell. idea why is?

#define kdefaulttableviewsectionheight 50  - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     return self.posts.count; }  - (nsinteger)numberofsectionsintableview:(uitableview *)tableview {     return 1; }  - (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath {     return kdefaulttableviewcellheight; }  - (cgfloat)tableview:(uitableview *)tableview heightforheaderinsection:(nsinteger)section {     return kdefaulttableviewsectionheight; }  - (uiview *)tableview:(uitableview *)tableview viewforheaderinsection:(nsinteger)section {      uiview *view = [[uiview alloc] initwithframe:cgrectmake(0, 0, self.view.frame.size.width, kdefaulttableviewsectionheight)];     uibutton *hot = [[uibutton alloc] initwithframe:cgrectmake(self.view.frame.size.width/2, 0, 100, kdefaulttableviewsectionheight)];     uibutton *new = [[uibutton alloc] initwithframe:cgrectmake(self.view.frame.size.width/2-100, 0, 100, kdefaulttableviewsectionheight)];     uiview *underline = [[uiview alloc] initwithframe:cgrectmake(new.frame.origin.x, view.frame.size.height-10, 70, 1)];     uiview *border = [[uiview alloc] initwithframe:cgrectmake(0, view.frame.size.height-1, view.frame.size.width, 1)];      [border setbackgroundcolor:[uicolor colorwithred:50.0/255.0 green:50.0/255.0 blue:50.0/255.0 alpha:1]];      self.underline = underline;      if (self.new)         [underline setcenter:cgpointmake(new.center.x, underline.center.y)];     else         [underline setcenter:cgpointmake(hot.center.x, underline.center.y)];      [underline setbackgroundcolor:[uicolor whitecolor]];     [view setbackgroundcolor:[uicolor blackcolor]];      [hot settitle:@"hot" forstate:uicontrolstatenormal];     [hot settag:2];     [hot settitlecolor:[uicolor whitecolor] forstate:uicontrolstatenormal];     [hot addtarget:self action:@selector(selectquerytype:) forcontrolevents:uicontroleventtouchupinside];     [hot.titlelabel setfont:[uifont fontwithname:@"avenir-heavy" size:20.0]];      [new settitle:@"new" forstate:uicontrolstatenormal];     [new settag:1];     [new settitlecolor:[uicolor whitecolor] forstate:uicontrolstatenormal];     [new addtarget:self action:@selector(selectquerytype:) forcontrolevents:uicontroleventtouchupinside];     [new.titlelabel setfont:[uifont fontwithname:@"avenir-heavy" size:20.0]];      [view addsubview:new];     [view addsubview:hot];     [view addsubview:underline];     [view addsubview:border];     return view; } 

i've tried following code fix issue, reduces space between top of uitableview , uinavigationbar:

    /*     if ([[uidevice currentdevice].systemversion floatvalue] >= 7){         self.posttableview.contentinset = uiedgeinsetsmake(-8, 0, 0, 0);     } */ 

but reduces spacing between top of uitableview , uinavigationbar.

enter image description here

i think confusing tableheaderview property section header view. delegate method tableview:viewforheaderinsection: calling sets header of section rather header of uitableview itself. in -numberofsectionsintableview: returning 1 section, add custom header header of tableview rather being header of first section in tableview. doesn't solve specific problem, seems better solution app considering there on 1 section in tableview.

in -viewdidload can set tableheaderview property custom view follows:

- (void)viewdidload{    //...    _tableview.tableheaderview = [self mytableheader];  }  - (uiview *)mytableheader{    //return custom header view   } 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -