iOS 10과 더불어 업데이트 된 Xcode 8.x 버전으로 기존 앱을 빌드 했을 때,

기존에 tableView Header를 커스텀 뷰로 개발하였을 때 section header view가 보이지 않는 문제가 생긴다.


해당 문제는 기존에는 디폴트 높이를 설정하지 않아도 알아서 높이가 들어 갔는데 이번 버전부터는 해당 기능이 삭제가 된듯(....)

앞으로 점점 스토리보드 위주로 갈 것이라고 생각했는데  이번 건은 오히려 스토리보드의 역할이 줄어든 듯한 느낌.. 다른 이유가 있겠지.

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 30;
}

위 코드를 추가 하여 높이를 지정해주면 다시 section header view가 나타난다!

이 사실을 알기 전까지는 커스텀 헤더 뷰 지원이 중단 된 줄 알았음 ㅠ_ㅠ


아래는 대략적인 헤더 뷰 생성 예제 코드

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    UIView *customTitleView = [ [UIView alloc] initWithFrame:CGRectMake(10, 0, 300, 44)];
    UILabel *titleLabel = [ [UILabel alloc] initWithFrame:CGRectMake(20, 0, 300, 44)];
    
    if(section == 0)
    {
        titleLabel.text = @"섹션1";
        titleLabel.textColor = UIColorFromHEX(0x008080);
        
    }
    else if(section == 1)
    {
        titleLabel.text = @"섹션2";
        titleLabel.textColor = UIColorFromHEX(0xFFCC66);
        
    }
    else
    {
        titleLabel.text = @"섹션3";
        titleLabel.textColor = UIColorFromHEX(0x1E90FF);
    }
     titleLabel.font = [UIFont fontWithName:@"NanumBarunGothic" size:16];
    titleLabel.backgroundColor = [UIColor clearColor];
    [customTitleView addSubview:titleLabel];
    
     return customTitleView;
}


+ Recent posts