2011-08-11 94 views
0

我們可以得到使用viewWithTag方法的特定標籤的觀點,像如何使用特定標籤設置UIButton的標題?

[sampleView viewWithTag:1]; 

但是如何才能一的setTitle的UIButton的特定標籤?

this answer here,它使用下面的代碼來設置alpha。但setTitle不會響應viewWithTag對不對?

UIView* view = [theViewContainingThatButton viewWithTag:tag]; 

view.alpha = 0.5; 

我甚至嘗試this question,但沒有運氣!

我還能在這裏做什麼?

感謝名單:)

回答

3
UIButton* aButton = (UIButton *) [theViewContainingThatButton viewWithTag:tag]; 

[aButton setTitle:@"clickeme" forState:UIControlStateNormal]; 
+0

感謝名單:)但是「ThatButton迴應'在'ContainingThatButton'和'aButton'中是不同的。我想要的是設置'ThatButton'的標題。我試過了,ThatButton = aButton;但沒有奏效。任何想法! –

2

下面應該工作:

UIButton *button = (UIButton *)[theViewContainingThatButton viewWithTag:tag]; 
[button setTitle:@"Button Title" forState:UIControlStateNormal]; 

記住,UIButton並不setTitle:迴應,但到setTitle:forState:

+0

但'theViewContainingThatButton'和'Button'中的'ThatButton'是不同的。我想要的是設置'ThatButton'的標題。我試過了,ThatButton = Button;但沒有奏效。任何想法! (是的,我的意思是setTitle:forState並使用相同的:) –

+0

@ S.Philip:這對我來說沒有意義。在上面的代碼片段中,'button'是一個指向'UIButton'標籤'tag'的指針。這段代碼將用標籤'tag'設置'UIButton'的標題。我不確定你還想做什麼。 – PengOne

+0

非常感謝您試圖幫助:)其實我的問題稍微複雜一點,我不能在這裏複製所有這些代碼來解釋。 Thanx無論如何:) –