I'm getting some odd behavior with my UITableView.
There's spacing between my UITableView Header and the first cell. Any idea why this 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 the following code to fix the issue, but this just reduces the space between the top of the UITableView and the UINavigationBar:
/*
if ([[UIDevice currentDevice].systemVersion floatValue] >= 7){
self.postTableview.contentInset = UIEdgeInsetsMake(-8, 0, 0, 0);
} */
but this just reduces the spacing between the top of the UITableView and the UINavigationbar.