2014-10-03 38 views
0

我創建了一個NSButton網格(見圖片)和setAction命令每個NSButton這樣的:找出哪些我NSButton被壓

[myButton setAction:@selector(buttonPressed)]; 

-(void)buttonPressed { //things run here 
    NSLog(@"Button pressed!%@", titleString); 
} 

不幸的是我不看怎麼弄的的冠軍按下了按鈕。我想檢索buttontitle並將它存儲在buttonPressed開頭的titleString

任何想法?

enter image description here

回答

0

我創建了一個IBAction爲得到發送我已經沒有成功嘗試過:

- (IBAction) buttonPressed:(id)sender { 
    NSString *titleStr = [sender title]; //getting the btn text 
    NSLog(@"Button '%@' pressed!", titleStr); 
} 

線索IST是buttonPressed必須跟一個冒號。現在它像一個魅力。

[myButton setAction:@selector(buttonPressed:)];