2013-01-18 31 views
0

如何獲取id和從@selector的另一個參數? ,即時嘗試,但不工作!問題與@selector調用方法與兩個參數

-(void)displayContent:(UIViewController *)currentView sender:(id)sender{} 

[button addTarget:self action:@selector(displayContent:self:)  forControlEvents:UIControlEventTouchUpInside]; 
+1

選擇器不調用方法,它只是**名稱**方法。一個非常重要的區別。 –

回答

0

Cocoa Fundamentals Guide: Communicating with Objects: Target-Action in UIKit

UIKit框架允許三種不同形式的動作選擇的:

- (void)action

- (void)action:(id)sender

- (void)action:(id)sender forEvent:(UIEvent *)event

你的方法-displayContent:sender:不匹配任何這些簽名的,所以它不是有效的傳遞給-[UIControl addTarget:action:forControlEvents:]。您必須找到另一種方法將currentView納入您的操作中,可能通過使用實例變量來跟蹤當前視圖。

+0

thnks ...我找到了另一種方式! – BaSha