Re: [問題] NSString 帶入判斷式

看板MacDev作者 ( )時間13年前 (2012/03/08 14:54), 編輯推噓3(301)
留言4則, 3人參與, 最新討論串2/2 (看更多)
打開Interface Builder 在你的Button的Button Attributes裡. 將Tag的值設成 1000~1xxxx (可任意) 然後在你的method裡寫 if(![sender isKindOfClass:[NSButton class]]){ return; } int buttontag = [sender tag]; switch (buttontag){ case 1000: // button 1000 has been pressed. break; case 1001: // button 1001 has been pressed. break; . . } ※ 引述《love100205mt (石炭石炭)》之銘言: : 各位高手!!請幫幫小弟 : 我利用了 : NSString *title= [sender titleForState:UIControlStateNormal]; : 抓到了我這個button的title : 可是把title帶入if判斷式內的時候 : 一直判斷錯誤 : 以下我的寫法 : 總共有四個按鈕其中一個的title是1 : if (title !="1") { : UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"正確" : message:@"接下去" : delegate:self : cancelButtonTitle:@"確定" : otherButtonTitles:nil]; : [alert show]; : [alert release]; : } : 總共有四個按鈕其中一個的title是1 : 結果四個按鈕都會跳出正確這個視窗 : 因為到這一步都無法正確所以沒有寫下面的 : 請各位高手幫我解答一下!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 203.69.87.123

03/08 15:13, , 1F
感謝高手教導,可是我用了isEqualToString就可以了
03/08 15:13, 1F

03/08 15:15, , 2F
用tag會是比較好的做法,button的title有可能(其實是應
03/08 15:15, 2F

03/08 15:16, , 3F
該要)localization,到時比不完的
03/08 15:16, 3F

03/08 15:16, , 4F
設tag是標準做法,比較title屬於偷懶(雖然很好用
03/08 15:16, 4F
文章代碼(AID): #1FM5Uh-p (MacDev)
文章代碼(AID): #1FM5Uh-p (MacDev)