2016-07-01 6 views
0

Objective C에서 다음을 구현하는 방법을 제안 해 줄 수 있습니까?섹션 펼치기 및 접기

섹션을 클릭하면 해당 섹션의 행이 펼쳐집니다. 클릭 한 섹션을 알 수 있으며 해당 섹션의 행 수를 반환하는 방법은 무엇입니까?

참고 : 내 섹션에는 버튼이 있습니다. 그리고 모든 섹션의 행을 클릭하면 펼쳐집니다. 다시 섹션을 클릭하면 모든 섹션의 행이 축소됩니다.

+0

이 링크를 참조하십시오 http://stackoverflow.com/questions/17248021/how-to-expand-and-collapse-rows-using-header-section-in-a-uitableview을의 –

+0

가능한 중복 [ 확장 및 축소 tableView 섹션 IOS?] (http://stackoverflow.com/questions/27729150/expanding-and-collapsing-tableview-sections-ios) – Jidong

답변

1

참고 : - 내있는 TableView 셀 높이가 126입니다,하지만 난 내 응용 프로그램을 실행할 때 (내가 아래 언급으로) 내가 자동으로 테이블 셀 높이가 확장보다 테이블 셀에 누르면, 테이블 셀의 높이가 75입니다.

참조 : - int myCurrentSelection = 9999; // 전역으로 설정합니다.

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 

int myrow = (int)indexPath.row; 

if (myCurrentSelection == myrow) { 
    myCurrentSelection = 9999; 
    cell.contentView.backgroundColor = [UIColor whiteColor]; 
} else { 
    myCurrentSelection = myrow; 
    cell.contentView.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0]; 
} 
[tableView beginUpdates]; 
[tableView endUpdates]; 
[self.tblView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES]; 
} 


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    CGSize boundingBox = [mutArrMessages [indexPath.row][@"message"] boundingRectWithSize:CGSizeMake((self.tblView.frame.size.width - 86),MAXFLOAT) 
                       options:NSStringDrawingUsesLineFragmentOrigin 
                      attributes:@{NSFontAttributeName:[UIFont helveticaNeueLightFontOfSize:17.0]} 
                       context:nil].size; 
CGSize size = CGSizeMake(ceil(boundingBox.width), ceil(boundingBox.height)); 
if ([indexPath row] == myCurrentSelection) { 
    return (MAX((size.height + 46),76)) + 50; 
} 
return (MAX((size.height + 46),76)); 
} 


-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath 
{  
return 76; 
}