2014-02-13 25 views
0

是否可以在UITapGestureRecognizer上作出分類?我想製作方便的方法來避免(alloc-init)遊戲。在uitapGestureRecognizer上做類別?

我厭倦了這一點:

+(void)tapDetector :(sel)selectormethod tags:(int)tag :tapsRequired:(int)taps{ 
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:ac action:@selector(??????????????????:)]; 
    singleTap.numberOfTapsRequired = tag; 
    singleTap.numberOfTouchesRequired = tag; 
} 

但問題是,我不能讓selectorMethod作爲動作參數......任何人都可以在這方面提供幫助? 。

+0

「prob is tha我不能得到selectorMethod作爲一個動作參數「爲什麼你不能?選擇器是一個可以作爲參數傳遞的對象,就像任何其他對象一樣。有什麼麻煩?你有什麼嘗試? – matt

回答

1

的選擇類型SEL(不SEL),你可以直接把它作爲行動(沒有 「@選擇......」 的東西如:

UITapGestureRecognizer * singleTap = [[UITapGestureRecognizer alloc]initWithTarget:ac action:selectormethod]; 

@selector(...)是一個編譯器指令使用編譯時符號信息將選擇器的字符串版本轉換爲常量SEL選擇器引用以供在運行時使用。在您的情況下,調用方將執行該工作,然後可以傳遞結果值。

相關問題