2014-01-07 7 views
-1

저는 맞춤 셀을 만드는 데 거의 새로운 제품입니다. 사용자 정의 셀이 있고 사용자 정의 버튼 (btnEdit)이있는 각 행에 6 개의 레이블이 작성되었습니다. 맞춤 검색 버튼이 .xib에서 삭제되었습니다. btnEdit은 두 레이블에 프레임을 만들고 해당 프레임을 클릭하면 제대로 작동하는 다른 함수를 호출합니다.셀에서 모든 라벨 레이어를 제거하는 방법

내가 가진 유일한 문제는 행에있는 btnEdit 중 하나를 클릭하면 제거되지 않는 한 다른 행에 클릭하지 않거나 하나를 선택하고 다른 하나를 클릭하면 해당 행이 제거됩니다. 먼저 다른 프레임.

여기 내 코드가 도움이 되길 바랍니다.

.H

@interface PositionTableCell : UITableViewCell { 
IBOutlet UILabel *lblSymbol; 
IBOutlet UILabel *lblSpl; 
IBOutlet UILabel *lblLpl; 
IBOutlet UILabel *lblrate; 
IBOutlet UILabel *lblAmount; 
IBOutlet UILabel *lblO; 
} 

@property (nonatomic, assign) BOOL isSelected; 
@property (nonatomic, assign) BOOL isRowSelected; 

@end 

하는 .m

- (IBAction)btnEdit:(id)sender 
{ 
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(value1)]; 
tapGestureRecognizer.numberOfTapsRequired = 1; 
[lblLpl addGestureRecognizer:tapGestureRecognizer]; 

UITapGestureRecognizer *tapGestureRecognizer2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(value2)]; 
tapGestureRecognizer2.numberOfTapsRequired = 1; 
[lblSpl addGestureRecognizer:tapGestureRecognizer2]; 

if (!isSelected){ 

    lblLpl.layer.borderColor = lblSpl.layer.borderColor = [UIColor blueColor].CGColor; 
    lblLpl.layer.borderWidth = lblSpl.layer.borderWidth = 5.0; 
    lblLpl.userInteractionEnabled = lblSpl.userInteractionEnabled= YES; 

    isRowSelected = YES; 
    isSelected = YES; 
} 

else if (isSelected){ 

    lblLpl.layer.borderColor = lblSpl.layer.borderColor = [UIColor clearColor].CGColor; 
    lblLpl.layer.borderWidth = lblSpl.layer.borderWidth = 0; 
    lblLpl.userInteractionEnabled = lblSpl.userInteractionEnabled= NO; 

    isRowSelected = NO; 
    isSelected = NO; 
} 

[tapGestureRecognizer release]; 
[tapGestureRecognizer2 release]; 

NSLog(@"CLICKED"); 
} 

답변

0

그것은 이전에 선택된 셀의 참조를 유지하여 해결 될 수있다.

처럼, 당신의하는 .m 파일에 변수를 선언 :

static PositionTableCell *previousCell = nil; 

과 같이 당신의 방법을 수정

- (IBAction)btnEdit:(id)sender 
{ 
    if (previousCell != nil && previousCell != self) 
    { 
     for (id subLabel in [[previousCell contentView] subviews]) 
     { 
      if ([subLabel isKindOfClass:[UILabel class]]) 
      { 
       UILabel *tempLabel    = (UILabel *)subLabel; 
       tempLabel.layer.borderColor  = [UIColor clearColor].CGColor; 
       tempLabel.layer.borderWidth  = 0; 
       tempLabel.userInteractionEnabled = NO; 

       isRowSelected = NO; 
       isSelected = NO; 
      } 
     } 
    } 


    // Other codes here 
}