2016-11-07 1 views
0

안녕 내 애플 리케이션에서 우리는 tableview 세포 편집 할 수 있어야한다는 요구 사항을 가지고, 의미 세포의 순서를 변경할 수 있습니다. 이 들어 reordercontrol 사용하고 있습니다. 이 재정렬 제어와 함께 오른쪽 끝뿐 아니라 전체 셀을 포함해야합니다. 이를 위해 나는 디스플레이 셀 방법에서 아래의 변경을 수행하고있다.버튼은 UIView에있는 이벤트를 받아 들일 수 있습니까?

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

     for (UIView * view in cell.subviews) 
     { 

      if ([NSStringFromClass([view class]) rangeOfString: @"Reorder"].location != NSNotFound) 
      { 


       // [view setBackgroundColor:[UIColor redColor]]; 

       UIView* resizedGripView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(view.frame), CGRectGetMaxY(view.frame))]; 
       [resizedGripView setBackgroundColor:[UIColor clearColor]]; 
       [resizedGripView addSubview:view]; 
       resizedGripView.backgroundColor=[UIColor clearColor]; 
       resizedGripView.userInteractionEnabled=YES; 

       [cell.contentView addSubview:resizedGripView]; 

       CGSize sizeDifference = CGSizeMake(resizedGripView.frame.size.width - view.frame.size.width, resizedGripView.frame.size.height - view.frame.size.height); 
       CGSize transformRatio = CGSizeMake(resizedGripView.frame.size.width/view.frame.size.width, resizedGripView.frame.size.height/view.frame.size.height); 

       // Original transform 
       CGAffineTransform transform = CGAffineTransformIdentity; 

       // Scale custom view so grip will fill entire cell 

       transform = CGAffineTransformScale(transform, transformRatio.width, transformRatio.height); 

       // Move custom view so the grip's top left aligns with the cell's top left 

       transform = CGAffineTransformTranslate(transform, -sizeDifference.width/2.0, -sizeDifference.height/2.0); 

       [resizedGripView setTransform:transform]; 


       for(UIImageView* cellGrip in view.subviews) 
       { 
        if([cellGrip isKindOfClass:[UIImageView class]]) 
         [cellGrip setImage:nil]; 
       } 
      } 
     } 
} 

내가 사용하는 셀은 맞춤 셀이며 셀은 아래처럼 보입니다.

Custom cell

제가 표시 셀에있어서의 변화를 상기 한 후. 오른쪽 가장자리뿐만 아니라 어디에서나 셀의 셀을 재정렬 할 수 있습니다. 우리가 볼 수 있듯이이 변경 후 기능적으로 작동하지 않는 셀에는 단추 하나가 제거되므로 단추 하나에 셀이 추가되기 때문에 기능이 작동하지 않습니다. 셀에서 사용할 수있는 구성 요소는 이벤트를 수락해야합니다. 제발 도와주세요.

답변

0

resizedGripView에서 cell.contentView까지를 추가 한 후 다른 컨트롤을 앞/뒤로 가져올 수있는 코드를 작성할 수 있습니다. 코드 아래에보십시오 :

[cell.contentView bringSubviewToFront:cell.btnPrice]; 
[cell.contentView bringSubviewToFront:cell.lblProduct]; 

이 컨트롤 btnPricelblProduct를 교체합니다.

희망이 있습니다.

+0

안녕하세요 milan 님의 회신에 감사드립니다. 그러나 그것은 작동하지 않습니다 : ( –

+0

안녕 milan 덕분에 그것은 큰 도움이됩니다. 나는 그것을 많이 고마워 작동시킬 수 있습니다. –

+0

다행 그것을 알았습니다. :) –

관련 문제