我有一個奇怪的問題與UIGestureRecognizerUIGestureRecognizer目標問題
我已經創建了一個類,其中我宣佈手勢識別,並把自我作爲目標
-(id)initWithTextView:(UITextView*)theTextView withDelegate:(id<WordSelectionDelegate>)theDelegate
{
if (self = [super init])
{
delegate = theDelegate;
textView = theTextView;
// init long press gesture to detect pressing on text elements
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressFromSender:)];
[textView addGestureRecognizer:longPressGesture];
}
return self;
}
但訣竅是當我實際上做出長按手勢,我有下一個錯誤:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteMutableAttributedString handleLongPressFromSender:]: unrecognized selector sent to instance 0x76227b0'
爲什麼消息自我去串?
上述代碼沒有任何問題。你必須擴大你的搜索範圍。在'handleLongPressFromSender'中放置一個斷點並確保它被調用(如果沒有,是否出現'WordSelection'對象超出範圍並被釋放給你?或者你輸入了錯誤的方法名嗎?或者只執行那個方法一個參數沒有正確的參數類型?)。如果它被調用,那麼再次擴大搜索範圍,看看你的'WordSelectionDelegate'定義,並確保你沒有問題。 – Rob 2012-08-08 16:28:22