我在使用UITapGestureRecognizer和UIButton的iPhone applcation中工作。我在self.view中添加了UITapGestureRecognizer。當我點擊UIButton時,它不會調用它的動作,只能調用tapiseure動作。如何解決這個問題?任何人都可以請幫忙解決這個問題嗎?UIButton操作不使用UITapGestureRecognizer iphone應用程序調用?
這是我在-ViewDidLoad
代碼,
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapFrom:)];
[self.view addGestureRecognizer:tapRecognizer];
[tapRecognizer release];
UIButton *infoButton1 = [UIButton buttonWithType:UIButtonTypeInfoDark];
infoButton1.frame = CGRectMake(0, 5, 30, 30);
infoButton1.tag = 1;
infoButton1.opaque = YES;
[infoButton1 addTarget:self action:@selector(infoAlert:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside];
[toolBarView1 addSubview:infoButton1];
-(void) infoAlert:(id) sender
{
NSLog(@"Get Info Alert"); // Here the control not calling..
}
-(void)handleTapFrom:(UITapGestureRecognizer *)recognizer
{
NSLog(@"%@",[NSString stringWithFormat:@"%d", recognizer.view.tag]); // Whenever i touch the button this method only calling.
}
請幫我解決這個問題。提前致謝。
謝謝。我在我的代碼中嘗試了這些項目。但我忘了提到delgate = self。這就是爲什麼我得到了答案。謝謝你的幫助。 – Gopinath 2012-07-24 13:49:55
您使用了哪兩種解決方案?第二種方法似乎更簡單 – Lefteris 2012-07-24 13:51:14
第二個答案我已經用來解決這個問題。非常感謝。 – Gopinath 2012-07-24 13:54:50