我有一個UITableView自定義單元格。每個單元格內有2個視圖。每個視圖都有一個UIGestureRecognizer,用於處理點擊事件。當點擊視圖時,我會向UINavigationController發送消息以推送詳細視圖。這種情況下工作正常,直到我實際上滾動表。表格滾動後,當用戶點擊單元格內的其中一個視圖時,應用程序崩潰。例如,我可以加載應用程序,點擊第二個單元格中的視圖,並將詳細視圖正確地推入屏幕。從那裏,我回到桌面,滾動到底部,回到頂部,並點擊相同的視圖。從那裏,應用程序崩潰與無法識別的選擇器錯誤。這是我設置的手勢(在viewDidLoad中):UITableView中的UIGestureRecognizer - 滾動後崩潰?
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleTap:)];
[self.view addGestureRecognizer:recognizer];
recognizer.delegate = self;
[recognizer release];
,這裏是要調用的方法:
-(void)handleTap:(UITapGestureRecognizer *)sender{
NSLog(@"Handling tap on ArticleTileViewController");
ArticleViewController *vc = [[ArticleViewController alloc] initWithArticleData:self.articleDataArray];
PROJECTAppDelegate *appDelegate = (PROJECTAppDelegate *)[UIApplication sharedApplication].delegate;
[appDelegate.navController pushViewController:vc animated:YES];
}[appDelegate.navController pushViewController:vc animated:YES];
}
最後,這裏是堆棧跟蹤我在控制檯中看到:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType handleTap]: unrecognized selector sent to instance 0x607ba30'
*** Call stack at first throw:
(
0 CoreFoundation 0x02839b99 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0298940e objc_exception_throw + 47
2 CoreFoundation 0x0283b6ab -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x027ab2b6 ___forwarding___ + 966
4 CoreFoundation 0x027aae72 _CF_forwarding_prep_0 + 50
5 UIKit 0x0057f060 -[UIGestureRecognizer _updateGestureWithEvent:] + 727
6 UIKit 0x0057b8bf -[UIGestureRecognizer _delayedUpdateGesture] + 47
7 UIKit 0x00580152 _UIGestureRecognizerUpdateObserver + 637
8 UIKit 0x00581464 _UIGestureRecognizerUpdateGesturesFromSendEvent + 51
9 UIKit 0x0032a844 -[UIWindow _sendGesturesForEvent:] + 1292
10 UIKit 0x003263bf -[UIWindow sendEvent:] + 105
11 UIKit 0x00309cb4 -[UIApplication sendEvent:] + 447
12 UIKit 0x0030e9bf _UIApplicationHandleEvent + 7672
13 GraphicsServices 0x02f07822 PurpleEventCallback + 1550
14 CoreFoundation 0x0281aff4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
15 CoreFoundation 0x0277b807 __CFRunLoopDoSource1 + 215
16 CoreFoundation 0x02778a93 __CFRunLoopRun + 979
17 CoreFoundation 0x02778350 CFRunLoopRunSpecific + 208
18 CoreFoundation 0x02778271 CFRunLoopRunInMode + 97
19 GraphicsServices 0x02f0600c GSEventRunModal + 217
20 GraphicsServices 0x02f060d1 GSEventRun + 115
21 UIKit 0x00312af2 UIApplicationMain + 1160
22 PROJECT 0x00002459 main + 121
23 PROJECT 0x000023d5 start + 53
24 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException
'
編輯:此測試了一段時間後,我已經確定,只有意見ŧ帽子在屏幕上可見時會觸發事件。所有其他崩潰與上述錯誤。可能與this未回答的問題?
這是我爲清楚起見省略頭聲明(IVARS和屬性:
@interface ArticleTileViewController : UIViewController<UIGestureRecognizerDelegate> {
}
-(void)handleTap:(UITapGestureRecognizer *)sender;
什麼類是「自我」,它有一個handleTap實現? – willcodejavaforfood 2010-10-12 14:11:47
self是ArticleTileViewController,它包含handleTap方法的實現 – 2010-10-12 14:15:24
您的代碼僅用於設置識別器委託才能調用可見的視圖嗎? – willcodejavaforfood 2010-10-12 14:15:41