2012-10-17 37 views
0

我有一個tableview與多個自定義按鈕。當我選擇一個按鈕,該按鈕應該突出顯示,如果我選擇任何其他按鈕上一個選定的按鈕應該自動unhighlight,從而突出顯示當前選定按鈕。我該怎麼做....?自動取消選擇iphonetable中的上一個選定的按鈕在iphone

-(IBAction)buttonPressed:(UIButton *)sender { 

tempBtn.selected = NO; 
    if (tempBtn != sender){ 
     tempBtn = sender; 
     tempBtn.selected =YES; 
     [ tempBtn setBackgroundColor:[UIColor redColor]]; 
    } 
    else{ 
     tempBtn = nil; 
    } 
} 

我在做這一點,但這裏所有我點擊都轉變爲紅色的按鈕不刪除prevoius選擇顏色(紅色)我..How能做到嗎?

+0

不清楚的問題! – Mutawe

回答

1

你是說如果它已經是紅色,它會變紅,但如果按鈕已經是紅色,你希望它變成另一種顏色/清晰?就好像你在選擇多行一樣?

tempBtn.selected = !tempBtn.selected; 
if(tempBtn.selected) 
{ 
    tempBtn.backgroundcolor = [UIColor redColor]; 
} 
else 
{ 
    tempBtn.backgroundcolor = [UIColor clearColor]; 
} 

編輯:由於輕微的問題更改

在您按下按鈕:

-(void)buttonPress:(id)sender 
{ 
    //Change Color to Red 
    if([myMutableArray count] > 0 
    { 
     UIButton* button = (UIButton *)[self.view viewWithTag:[myMutableArray objectAtIndex:0]; 
     button.setBackgroundColor = [UIColor clearColor]; 
     [myMutableArray removeAllObjects]; 
    } 
    [myMutableArray addObject:[sender tag]]; 
} 
+1

沒有我的意思是我有一些gridview中的許多按鈕。當我選擇其中應該是紅色的一個按鈕,如果我選擇另一個按鈕,那麼以前選擇的按鈕應該是清晰的顏色,並且呈現選擇的按鈕應該是紅色的。 donno知道如何得到它... – 07405

相關問題