viewforheaderixection의 프레임은 항상 같은 크기입니다
-
20-09-2019 - |
문제
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if(section != 0) {
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 30)] autorelease];
view.backgroundColor = [UIColor redColor];
return view;
} else {
return tableView.tableHeaderView;
}
}
이것은 내 viewforheaderixection의 구현이지만 내가 만드는 프레임은 항상 같은 빨간색 프레임을 보여줍니다. 내 코드에 문제가 있습니까?
영상:
업데이트:
MHM 이제 내 빨간색 블록이 높지만 첫 번째 테이블 헤더는 이제 어떻게 든 숨겨져 있습니다. 첫 번째는 TitleForHeadErisection으로 구현되었습니다. 나는 단지 테이블 헤더 높이의 높이를 구현한다고 생각했지만 작동하지 않습니다.
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if(section == 1)
return 30;
else
return tableView.tableHeaderView.frame.size.height;
}
해결책
이 대표 방법을 구현해야합니다
- (CGFloat)tableView:(UITableView *)tableView
heightForHeaderInSection:(NSInteger)section;
귀하의 경우에는 간단히 할 수 있습니다 return 30;
.
또한, 당신은 새고 있습니다 view
!
당신의 [view release]
이후에 발생합니다 return
. 그러나 곧 return
메소드 실행이 중단되고 귀하는 발생합니다 release
호출되지 않았습니다.
그래서 당신은 대신 이것을 원합니다
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 30)] autorelease];
그리고 명시 적을 제거하십시오 release
아래로.
제휴하지 않습니다 StackOverflow