올바른 대리자 및 데이터 소스 연결을 사용하여 tableview를 설정했습니다. reloadData 메소드는 데이터 소스 및 대리자 메소드를 제외하고 호출합니다. viewForHeaderInSection:
.
왜 이렇게이다?
답변
를 사용 tableView:viewForHeaderInSection:
하려면 구현해야합니다 tableView:heightForHeaderInSection:
. 헤더에 적절한 0이 아닌 높이를 반환해야합니다. 또한 구현하지 않아야합니다 tableView:titleForHeaderInSection:
. 둘 중 하나만 사용해야합니다 ( viewForHeader
또는 titleForHeader
).
답변
트릭은 두 가지 방법에 속해 있다는 것이다 UITableView
프로토콜 : tableView:titleForHeaderInSection:
A는 UITableViewDataSource
프로토콜있어서, 여기서이 tableView:viewForHeaderInSection
속하는UITableViewDelegate
.
그것의 의미는:
-
당신이 메소드를 구현하지만, 단지 자신을 할당하면
dataSource
에 대한UITableView
당신의
tableView:viewForHeaderInSection
구현은 무시됩니다. -
tableView:viewForHeaderInSection
우선 순위가 더 높습니다. 당신이 방법 모두를 구현하고 모두 자신을 할당하는 경우
dataSource
와delegate
에 대한UITableView
, 당신은 섹션 헤더의 뷰를 반환하지만이
tableView:titleForHeaderInSection:
무시됩니다.
나는 또한 제거를 시도했다 tableView:heightForHeaderInSection:
; 그것은 잘 작동했으며 위의 절차에 영향을 미치지 않는 것 같습니다. 그러나 문서는 tableView:viewForHeaderInSection
올바르게 작동 하는 데 필요하다고 말합니다 . 안전을 위해서도 이것을 구현하는 것이 현명합니다.
답변
현실에서 : @rmaddy 두 번 규칙을 허위했다 tableView:viewForHeaderInSection:
않습니다 하지 당신은 또한 구현하는 것이 필요 tableView:heightForHeaderInSection:
하고, 또한 모두 전화를 완벽하게 괜찮 titleForHeader
와 viewForHeader
. 나는 기록에 대해서만 규칙을 올바르게 진술 할 것입니다.
규칙은 단순히 viewForHeader
헤더에 높이를 지정하지 않으면 호출되지 않습니다. 세 가지 방법을 조합하여이 작업을 수행 할 수 있습니다.
-
구현
tableView:heightForHeaderInSection:
. -
테이블을 설정하십시오
sectionHeaderHeight
. -
호출하십시오
titleForHeader
(그렇지 않으면 헤더에 기본 높이가없는 경우 기본 높이가 제공됩니다).
이러한 작업을 수행하지 않으면 헤더 viewForHeader
가 없으며 호출되지 않습니다. 높이가 없으면 런타임에서 뷰의 크기를 조정하는 방법을 알지 못하므로 요청하지 않아도되기 때문입니다.
답변
기부 estimatedSectionHeaderHeight
와 sectionHeaderHeight
가치관으로 내 문제가 해결되었습니다. 예를 들어
self.tableView.estimatedSectionHeaderHeight = 100
self.tableView.sectionHeaderHeight = UITableViewAutomaticDimension
답변
rmaddy의 대답에서 헤더보기를 숨기려고하고 “tableView : heightForHeaderInSection”에 대해 0.0f를 반환하고 높이를 0으로 설정했습니다. tableView:viewForHeaderInSection
.
변경 후에서 return 1.0f
행 return 0.0f
에서 tableView:heightForHeaderInSection
대리인 방법tableView:viewForHeaderInSection
참으로 불렸다.
“tableView : heightForHeaderInSection”을 사용하지 않고도 원하는 효과를 얻을 수 있습니다. 그러나 이것은 “tableView : heightForHeaderInSection”델리게이트 메소드 호출에 문제가있는 다른 사용자에게 유용 할 수 있습니다.
답변
tableView:heightForHeaderInSection:
헤더의 높이를> 0으로 구현 하고 설정 해야합니다 .
이 델리게이트 메소드는 메소드와 함께 진행됩니다 viewForHeaderInSection:
.
이게 도움이 되길 바란다.
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 40;
}
답변
tableView:heightForHeaderInSection:
returns 구현이 있다면 UITableViewAutomaticDimension
,tableView:viewForHeaderInSection:
호출되지 않습니다.
UITableViewAutomaticDimension
UITableViewHeaderFooterView
delegate 메소드로 채워진 표준 이 사용 된다고 가정합니다 tableView:titleForHeaderInSection:
.
의 의견에서 UITableView.h
:
이에서 값 반환
tableView:heightForHeaderInSection:
또는tableView:heightForFooterInSection:
맞는 값에서 반환하는 높이 결과tableView:titleForHeaderInSection:
또는tableView:titleForFooterInSection:
제목 경우 것은 전무 없습니다.
