가 나는 UITableView
하고 "위임"과 "데이터 소스"내가 reloadData
를 호출 할 때마다 설정을했다라고는 방법으로 진행된다viewForHeaderInSection : 때 reloadData 호출되지는 :
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.headersList count];
}
및 방법 :
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
SectionInfo *headerInfo = (self.headerInfoArray)[section];
NSInteger numOfObjectsInSection = [[headerInfo.list objectsInList] count];
return headerInfo.open ? numOfObjectsInSection : 0;
}
그리고 나서 멈추십시오! 그것은 ViewForHeaderInSection:
방법으로 들어 가지 않습니다. 나는 열기/닫기 섹션 기능을 사용하는 것이 알고
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return SECTION_HEADER_HEIGHT;
}
- : 나는 또한 방법을 구현! 따라서 처음에는 모든 섹션이 닫히고 각 섹션의 행 수가 0이지만 반환되는 섹션의 수는 정확합니다 (섹션이 열리면 행 수가 업데이트됩니다).
- 헤더보기를 표시하는 유일한 방법은 자동으로 다시로드 될 때까지 잠시 기다리는 것입니다. 아니면 위아래로 스 와이프 해!
viewForHeaderInSection
방법 :
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UISectionHeaderView *sectionHeaderView = [[UISectionHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, SECTION_HEADER_HEIGHT)];
SectionInfo *sectionInfo = (self.headerInfoArray)[section];
sectionHeaderView.open = sectionInfo.open;
sectionInfo.headerView = sectionHeaderView;
sectionHeaderView.titleLabel.text = [NSString stringWithFormat:@"%@ (%lu)",sectionInfo.list.title, (unsigned long)[sectionInfo.list.objectsInList count]];
sectionHeaderView.section = section;
sectionHeaderView.delegate = self;
return sectionHeaderView;
}
당신의 클래스를'dataSource'와'UITableView'의'delegate' 둘 다로 설정했다고 가정하겠습니다, 맞습니까? – dasblinkenlight
reload 섹션 메소드를 사용하여 다른 접근 방법을 시도 할 수도 있습니다. 테이블 뷰 헤더 및 푸터 뷰 데이터 소스 콜백을 표시하여 문제가 있는지 확인하십시오. – J2theC
yah, 데이터 소스 및 위임에 아무 문제가 없습니다. 이 동작은 모든 섹션이 닫힌 경우에만 발생합니다. – a7md