2014-04-03 13 views
-2

我想選擇一個UILongPressGestureRecognizer操作相關聯,並且選擇對應於接收一個參數的函數。與參數選擇加入一個動作

所以我的問題是,我怎麼能設置UILongPressGestureRecognizer行動選擇,並將它傳遞參數?

我的功能(選擇)是:

-(void)MyFunction:(NSInteger)paramether 
{ 
    //some code 
} 

,我把它在UILongPressGestureRecognizer這裏:

longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(MyFunction)]; 

如果MyFunction的有任何paramether它會工作正常,但如果我將其設置爲接收一些paramether它不會工作

+0

爲了避免'無法識別的選擇器'錯誤,請使用'@selector(MyFunction :))'替換'@selector(MyFunction)'。 – Larme

+0

問題不完全在於此。 但如何傳遞給myFunction – mmarques

+0

例如,我想這樣做@選擇一個特定的值(MyFunction的:4) 和4是給myFunction的說法 – mmarques

回答

2

不能爲目標 - 動作登記(除(ID)發送方)添加使用的參數。但是您可以使用UIGestureRecognizerDelegate中的方法。你也可以從(id)發件人檢索一些有用的信息。