2014-07-10 3 views
0

스타일로 설정된 UITableView이 있습니다. 섹션에 하나 이상의 항목이 있으면 섹션 헤더 아래에 한 픽셀 구분 기호가 표시됩니다. 그러나 섹션에 항목이 없으면 섹션 사이에 구분 기호가 없습니다.빈 섹션에 대한 테이블보기 구분 기호 표시

셀이없는 섹션을 포함하여 모든 섹션에 구분 기호를 표시하려면 어떻게해야합니까?

enter image description here

공지 사항 섹션 1과 2는 그들과 그들의 첫 번째 셀 사이의 구분을 가지고 있지만 섹션 3이 절 사이에 구분이없는 방법 4.

답변

0

당신은 당신의 섹션을 사용자 정의 시도 할 수 있습니다 헤더보기. 이 대리자 funciton을 사용하십시오 : - (UIView *) tableView : (UITableView *) tableView viewForHeaderInSection : (NSInteger) section;

1

섹션간에 구분 기호를 추가하려면이 두 가지 방법을 사용하십시오.

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 
{ 
    return 44.0; 
} 
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)]; 

    [headerView setBackgroundColor:[UIColor brownColor]]; 
    UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(0, 43, 320, 1)]; 
        img.backgroundColor = [UIColor whiteColor]; 

    [headerView addSubview:img]; 
    return headerView; 
} 
1

하나의 솔루션은 각각의 빈 부분에 바닥 글을 추가하는 것입니다

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { 
    return [self tableView:tableView numberOfRowsInSection:section] == 0 ? 0.5 : 0.00000001; 
} 

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { 
    if ([self tableView:tableView numberOfRowsInSection:section] == 0) { 
     UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.5)]; 
     view.backgroundColor = tableView.separatorColor; 
     return view; 
    } else { 
     return nil; 
    } 
} 

주 :

이 올바른 대부분의 시간의 결과를 생성합니다

enter image description here

을 ...하지만 몇 가지 문제점이있다 : 당신이를 표시해야하는 경우, 그래서 이것은 바닥 글을 이용

  1. 을 바닥 글,이 솔루션은 아마도 작동하지 않습니다.
  2. 편집 모드에서 섹션의 마지막 항목을 끌면 해당 섹션과 그 섹션 사이의 경계가 사라집니다.
  3. 편집 모드에서 항목을 빈 섹션으로 드래그하면 섹션 아래쪽에 이중 테두리가 생깁니다.

문제 2의 실시 예 3 : 모든 항목에 해당 부로부터 이동 된 이후 부분 (2, 3) 사이에 라인이 없다 방법

상기 이미지에서

enter image description here

(알 문제 2).

또한 섹션 3과 4의 마지막 항목이 새로운 섹션으로 드래그 되었기 때문에 두 번 겹쳐져 보입니다 (문제 3).