標題很好解釋,但我有一個UITableView,我用自定義的UITableViewCells填充。我有一個UITapGestureRecognizer添加到UITableView中的UITableViewCell中的UIViewController的視圖,爲什麼它不會觸發?
在這些自定義UITableViewCells內部,我添加了顯示自定義圖像的自定義UIViewControllers。
對此UIViewController的UIView的,我增加了UITapGestureRecognizer如下:
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleTap:)];
recognizer.numberOfTapsRequired = 1;
recognizer.delegate = self;
[self.imageView addGestureRecognizer:recognizer];
[recognizer release];
}
-(void)handleTap:(UITapGestureRecognizer *)sender{
NSLog(@"Handling tap on ArticleTileViewController");
}
當我運行應用程序時,將細胞填充圖像偉大的,但是當我點擊圖片(或自定義的UIViewController上), 什麼都沒發生!我的NSLog不會啓動。我現在已經查看了一個小時的代碼,並沒有看到我出錯的地方。
有人看到我失蹤的東西嗎?或者他們之前遇到過這種情況?
我認爲這將是最好有一個UIView或UIImageView的子類,而不是使用一個UIViewController的。除非你的視圖太複雜了,否則最好是UIView而不是UIViewController。在你的情況下,只是顯示一個自定義圖像,它聽起來是爲UIImageView子類或甚至可能只是UIImageView而定製的。 –