2011-04-27 4 views
0

나는 tableHeaderView로 간단한 uitableview 있습니다. 나는 하나 이상의 섹션을 가지고있다.uitableheader를 첫 번째 표 셀 바로 위에 놓을 수 있습니까?

헤더 뷰의 높이를 30으로 설정했지만 내 머리글에서 40 픽셀 높이의 uiview를 사용하고 싶습니다. (0,0 ~ 320,30 투명하지 않음, 30,10 ~ 320,40은 투명 함). 나는 그 안에 그림을 넣었다. 점 (0x30)에 작은 아이콘이 있습니다. 높이 = 10. 난 단지 첫 번째 tablecell에 조금 이상 내 headerview를 보여주고 싶습니다.

아래와 같이 헤더 높이를 30으로 설정했지만 viewForHeaderInSection에서 40 픽셀 높이보기를 만듭니다.

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { 
    return 30; 
} 

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 


    UIView *sectionView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)]; 
    sectionView.backgroundColor = [UIColor redColor]; 
    [sectionView autorelease]; 
    return sectionView; 

} 

가능합니까?

답변

0

섹션 뷰는 헤더의 높이에 따라 제한됩니다. 1000 픽셀 높이의 UIView를 사용하는 경우에도 테이블 셀/머리글의 높이로 정의 된 제한 내에서만 표시됩니다.

+0

그래서 불가능한가요? – fulberto100

+0

누군가가 전에 발견되지 않은 왜곡 된 해결 방법을 제시하지 않는 한, 지금까지는 내 지식으로는 불가능합니다. –

0

아마도 귀하의 문제에 대한 답변을 가지고 있습니다. 이것이 좋은 해결책인지는 모르겠지만 괜찮다고 생각합니다.

새 xib 파일을 만들고 해당 파일에 UITableViewCell을 넣습니다. UITableViewCell의 높이를 54로 변경하고 UIView를 UITableViewCell에 넣습니다. 보기의 프레임은 0,0,320,10입니다. 그런 다음 해당 xib 파일의 파일 소유자를 TableViewController로 변경했습니다.

@interface RootViewController : UITableViewController { 

UITableViewCell * firstCellInSection; 

} 

@property (nonatomic, retain) IBOutlet UITableViewCell * firstCellInSection; 
@end 

그 후 저는 firstCellInSection Outlet을 xib 파일의 UITableViewCell과 연결했습니다.

@synthesize firstCellInSection; 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
UITableViewCell * cell; 
if (indexPath.row == 0) { 
    if (indexPath.row == 0) { 
     static NSString *firstCellInSectionIdentifier = @"FirstCellInSectionIdentifier"; 
     cell = [tableView dequeueReusableCellWithIdentifier:firstCellInSectionIdentifier]; 
     if (cell == nil) { 
      [[NSBundle mainBundle] loadNibNamed:@"FirstCell" owner:self options:nil]; 
      cell = firstCellInSection; 
      self.firstCellInSection = nil; 
     } 
    } 

} 

else { 

    static NSString *CellIdentifier = @"Cell"; 

    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

} 



// Configure the cell. 
return cell; 
} 

사용자 정의 행 높이 :

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 

if (indexPath.row == 0) return 54; 

else return 44; 
} 

에서

은 그럼 여기

indexPath.row == 0 

모든 셀의있는 TableView 하중이 firstCell는 코드의 코드를 변경 headerView에 대한 코드와 결합하여 원하는 것처럼 보일 수 있습니다.

+0

나는 당신의 솔루션을 아직 시도하지 않았다. 솔루션에 따르면 첫 번째 셀은 다른 셀보다 커집니다 (10 픽셀). – fulberto100

+0

네 셀이 10 픽셀 높습니다. –

+0

하나의 문제가 있다고 생각합니다. 사용자가 스크롤하면 첫 번째 셀이 사라지고 모든 셀은 동일해질 것입니다. – fulberto100