得到Interface Builder的名稱。如果我的名字在Interface Builder一個小部件,然後我寫接收點擊該按鈕事件的方法:如何從ID
- (IBAction)btnTouchDown:(id)sender
{
// how can you identify the button here,
// if several different buttons map
// their "Touch" event to this same function?
// I know you can look at its text but that seems really clumsy
// can I somehow get its INTERFACE BUILDER NAME?
// I named each uniquely in interface builder,
// under "Identity"/"Name"
// Or is my only recourse to tie EACH BUTTON to its own handler function?
}
但我想使用_the same_函數來處理按鈕。我不能在我的事件處理程序中使用IF語句並檢查「哪個按鈕被按下」這種方式? – bobobobo 2009-11-01 03:53:08
我在最近的編輯中添加了這個。你可能會認爲這是一個簡單的方法,但是如果你有不同的方法處理不同的邏輯路徑,那就容易多了。這樣,一個大功能就不會被按鈕的處理程序分支之一的錯誤搞亂。它更易於維護。但就像我說的,如果你真的想檢查標籤屬性。你說的檢查文本笨拙(並且不必要的昂貴)是正確的,但關於使用一個處理所有按鈕的大方法也可以這麼說。 – 2009-11-01 03:58:30
請超級大膽的單詞__tag number__:D – bobobobo 2009-11-01 04:56:42