2014-01-07 79 views
-1

我幾乎是新來創建自定義單元格。我有一個自定義單元格,並在每行上用自定義按鈕創建了6個標籤(btnEdit)。自定義按鈕被從.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 
} 
相關問題