0

我在向我的应用程序添加目标/操作方法时遇到问题。这是我的代码:

-(void)printInConsole
{
  NSLog(@"2");
}

-(void)createGCButton
{
  UIButton * LButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  LButton.frame = CGRectMake(200, 90, 100, 50);
  [LButton setTitle:@"L" forState:UIControlStateNormal];
  [self.view addSubview:LButton];
  [LButton addTarget:self action:@selector(printInConsole)forControlEvents:UIControlEventTouchUpInside];
}

所以首先我尝试了一种游戏中心方法,但我没有工作。现在我添加了这个简单的 NSLog 方法,它也不起作用。控制台什么也不写。那么问题出在哪里。如果您需要有关我的代码的更多详细信息,请说出来,我会发布它。上帝保佑解决这个问题的人。

问候,克莱门

4

1 回答 1

1

问题很可能与UITapGestureRecognizer. 你可以看到我就这个问题发表的这篇博文。

基本上你需要实现一个UITapGestureRecognizer委托方法并告诉它不要弄乱按钮。

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    return ![touch.view isKindOfClass:[UIButton class]];
}
于 2012-05-21T12:42:26.340 回答