UitableView의 섹션 헤더의 기본 높이
-
05-07-2019 - |
문제
uitableview에서 첫 번째 헤더의 높이를 설정하고 싶습니다. 다른 헤더의 경우 기본 높이를 유지하기를 원합니다. 아래 코드에서 "Somedefaultheight"를 대신 할 수있는 가치/상수는 무엇입니까?
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 0)
return kFirstHeaderHeight;
return someDefaultHeight;
}
감사
해결책
iOS 5.0 이후에는 대부분의 대의원 방법에서 uitableviewautomaticimension을 반환 할 수 있습니다. 문서 페이지 하단에 있습니다
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if(section == CUSTOM_SECTION)
{
return CUSTOM_VALUE;
}
return UITableViewAutomaticDimension;
}
다른 팁
내 앱의 기본값을 확인하면 그룹화 된 테이블의 경우 기본값은 22이고 그룹화되지 않은 테이블의 경우 기본값은 높이가 10입니다.
테이블 뷰에서 속성 섹션 HeaderHeight의 값을 확인하면 알려야합니다.
실제로 트릭을 수행합니다 :)
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if(section == 0)
return kFirstSectionHeaderHeight;
return [self sectionHeaderHeight];
}
완전성을 위해 : iOS7+에서 그룹화 된 스타일 섹션 헤더의 높이는 다음과 같습니다. 55.5
첫 번째와 38
다음 헤더를 위해. (dcintrospect로 측정)
정답이 무엇인지 잘 모르겠지만 10 또는 22는 iOS 5에서 그룹화 된 테이블보기의 올바른 높이로 보이지 않습니다. 이것 질문은 적어도 거의 올바른 높이로 보입니다.
기본 높이를 얻으려면 그냥하자 super
처리해:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 0)
return kFirstHeaderHeight;
return [super tableView:tableView heightForHeaderInSection:section];
}
Swift 4.2의 경우 uitableview.automaticimension을 반환해야합니다
이것은 트릭을 수행해야합니다
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.section == CUSTOM_SECTION)
{
return CUSTOM_VALUE;
}
return [tableView rowHeight];
}
제휴하지 않습니다 StackOverflow