2014-11-04 3 views
1

저는 iOS 개발에 초보자입니다.이 질문은 여러 번 묻지 만 혼란 스럽습니다. 섹션에서 UITableview 셀 사이의 공간을 설정하는 방법을 알고 싶습니다. 내 응용 프로그램 UITableview 두 섹션의 첫 번째 섹션에서 단 하나의 데이터 값을 포함하므로 모든 문제가 없습니다. 하지만 내 두 번째 섹션은 5 7 데이터 값을 포함하지만 UITableview에서 두 번째 섹션 셀 사이에 바닥 글에 공간을 설정하는 방법 그들 사이의 공간이 아닙니다. 이 섹션 iOS의 Tableview 셀 사이에 간격을 설정하는 방법은 무엇입니까?

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

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section 

두 가지 방법이 있지만 하나의 섹션에서 세포 사이의 공간을 퍼팅의 목적에 부합하지 둘 수 있도록

+0

셀 또는 섹션 사이에 공백을 원하십니까? – Zigglzworth

+0

세포 대신에 솜씨보기를 사용하십시오 –

+0

벼룩의 대답을 참조하십시오 : http://stackoverflow.com/questions/6216839/how-to-add-spacing-between-uitableviewcell – Zigglzworth

답변

2

확인을 클릭합니다. 내 돈 들어

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView에서

  1. 해키 첫 번째이자 가장 복잡한 두 가지 옵션이 ... /가 두 번째 섹션과 cellForRowAtIndexPathif (section == 0)에있는 세포의 수를 반환 할 수는의 데이터를 넣어 보통의 방법으로 ... else[theArray objectAtIndex:indexPath.section]을 대신 사용하여 배열 밖으로 정보를 가져올 수 있습니다.

  2. (훨씬 더 간단하고 더 나은 실천)에 ..있는 UITableViewCell 하위 클래스를 생성하고 설정할 수하는 .m 사용자 정의 셀에 너무

    (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
    static NSString *CellIdentifier = @"Cell"; 
    static NSString *MyCellIdentifier = @"MyCustomCell"; 
    
    switch (indexPath.section) { 
        case 0: 
        { 
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    
        if (!cell) 
         cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    
        // setup your 1st section cells here 
    
        return cell; 
    
        } 
         default: 
        { 
         MYTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyCellIdentifier]; 
    
         if (!cell) 
          cell = [[MYTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyCellIdentifier]; 
    
         // all other layout code here if indexPath.row == 0 etc. 
    
         return cell; 
        } 
    } 
    

처럼 cellForRowAtIndexPath에 그것을 사용

-(void)layoutSubviews 
{ 
    [super layoutSubviews]; 
    self.imageView.frame = CGRectMake(0,0,0,0); // lay them out at the top/middle/wherever in your cell 
    self.textLabel.frame = CGRectMake(0,0,0,0); // which will allow for some space at the bottom/edges 
} 

이 방법을 사용하면 셀 자체에서 패딩을 설정할 수 있습니다.이 패딩은 더 깨끗하고 재사용이 가능합니다. 당신이 간격을 표시하기 위해 다른 색상을 원하는 경우에, 당신은 사용자 정의있는 UITableViewCell 하위 클래스 방법

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 

에 UIViews를 만들어야하고 이미지/내용이있는 경우 [UIColor clearColor];에 당신이 항상 셀의 backgroundColor 설정할 수 있습니다 [self.contentView addSubView:someView];를 사용하여 추가 tableView 뒤

관련 문제