2013-08-19 2 views
0

하나의 git 허브 자습서에서 plist 값을 사용하여 테이블 뷰를 확장 및 축소합니다. 그 자습서에서 내가 행을 누를 때 확장되고 있습니다. 동일한 행을 누르면 다시 문제가 없습니다. 그러나 내가 원하는 것은 행을 누르면 다른 행이 열리게 될 것이라고 기대할 때입니다. 그래서 어느 누구도 나에게 약간의 아이디어를 줄 수 있습니다. 확대/축소 ios에서 선택된 다른 행을 셀 축소 행

는 한 번에 정확히 하나의 셀을 확장하려는 의미 확장하고

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 

    NSDictionary *d=[self.arForTable objectAtIndex:indexPath.row]; 
    NSLog(@"%@",d); 
    if([d valueForKey:@"Objects"]) { 
     NSArray *ar=[d valueForKey:@"Objects"]; 
     NSLog(@"%@",ar); 


     BOOL isAlreadyInserted=NO; 

     for(NSDictionary *dInner in ar){ 
      NSInteger index=[self.arForTable indexOfObjectIdenticalTo:dInner]; 
      NSLog(@"%ld",(long)index); 


      isAlreadyInserted=(index>0 && index!=NSIntegerMax); 
      if(isAlreadyInserted) break; 
     } 

     if(isAlreadyInserted) 
     { 
      [self miniMizeThisRows:ar]; 
     } 
     else 
     { 
      NSUInteger count=indexPath.row+1; 
      NSMutableArray *arCells=[NSMutableArray array]; 
      for(NSDictionary *dInner in ar) { 
       [arCells addObject:[NSIndexPath indexPathForRow:count inSection:0]]; 
       [self.arForTable insertObject:dInner atIndex:count++]; 
      } 




      [tableView insertRowsAtIndexPaths:arCells withRowAnimation:UITableViewRowAnimationLeft]; 
     } 
    } 
} 

-(void)miniMizeThisRows:(NSArray*)ar{ 

    for(NSDictionary *dInner in ar) { 
     NSUInteger indexToRemove=[self.arForTable indexOfObjectIdenticalTo:dInner]; 

     NSArray *arInner=[dInner valueForKey:@"Objects"]; 
     if(arInner && [arInner count]>0){ 
      [self miniMizeThisRows:arInner]; 
     } 

     if([self.arForTable indexOfObjectIdenticalTo:dInner]!=NSNotFound) 
     { 
      [self.arForTable removeObjectIdenticalTo:dInner]; 
      [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject: 
               [NSIndexPath indexPathForRow:indexToRemove inSection:1] 
               ] 
           withRowAnimation:UITableViewRowAnimationRight]; 
     } 
    } 
} 
+0

해결책을 찾았습니까? 나는 또한 같은 해결책을 찾고있다 ... –

+0

Fahim 형제는 이것에 대한 해결책이 있나? – user3182143

답변

0

붕괴에 대한 코드입니다. 따라서 마지막으로 확장 된 행의 인덱스 경로를 저장해야하며 해당 인덱스 경로에 대해 메서드를 호출해야하며 동시에 확장 할 것으로 예상되는 행에 대해 셀을 삽입해야합니다.

UPDATED .H

NSIndexPath * lastIndexPath에 메이크 멤버 변수;

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     [tableView deselectRowAtIndexPath:indexPath animated:YES]; 


      if(lastIndexPath.row == indexPath.row) 
      { 
      NSDictionary *d=[self.arForTable objectAtIndex:indexPath.row]; 
     if([d valueForKey:@"Objects"]) { 
      NSArray *ar=[d valueForKey:@"Objects"]; 
       } 
      [self miniMizeThisRows:ar]; 
      } 

      else 
      { 
       if(lastIndexPath.row) 
       { 
        NSDictionary *d=[self.arForTable objectAtIndex:lastIndexPath.row]; 
        if([d valueForKey:@"Objects"]) { 
        NSArray *ar=[d valueForKey:@"Objects"]; 
        [self miniMizeThisRows:ar]; 
        } 
       } 
       NSUInteger count=indexPath.row+1; 
       NSMutableArray *arCells=[NSMutableArray array]; 
       for(NSDictionary *dInner in ar) { 
        [arCells addObject:[NSIndexPath indexPathForRow:count inSection:0]]; 
        [self.arForTable insertObject:dInner atIndex:count++]; 
        lastIndexPath = indexPath; 

       [tableView insertRowsAtIndexPaths:arCells withRowAnimation:UITableViewRowAnimationLeft]; 
      } 
     } 
    } 

브래킷을 놓친 경우 사용하시기 바랍니다. 그것에 대해 저에게 알려주십시오.

+0

나는 그것을 관리 할 수있는 방법을 완전히 3 단계로 가지고있다. –

+0

Vijay_07 과거 3 단계의 모든 코드를 확장 해주세요. You.i와 같은 조건 3 단계 확장 및 축소 및 3 단계 레이블 검색이 필요합니다. –

관련 문제