信息按钮未链接到其他视图控制器

时间:2012-09-04 14:54:55

标签: ios cocoa-touch uibutton segue

我有一个信息按钮,在相机视图顶部显示为叠加UIView,但未链接到所需的视图控制器。触摸时没有任何事情发生。

以下是创建按钮并将其链接的代码

    // Create a Button to get Help
    infoButton =  [UIButton buttonWithType:UIButtonTypeInfoLight ] ;
    CGRect buttonRect = infoButton.frame;

    // Calculate the bottom right corner
    buttonRect.origin.x = 455;
    buttonRect.origin.y = 297;
    [infoButton setFrame:buttonRect];

    [infoButton addTarget:self action:@selector(presentInfo) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:infoButton];

以下是创建segue的代码

- (void) presentInfo
{
InfoViewController *ivc = [self.storyboard instantiateViewControllerWithIdentifier:@"InfoViewController"];
[self presentModalViewController:ivc animated:YES];
}

1 个答案:

答案 0 :(得分:1)

首先尝试: - 在:

中设置断点
- (void) presentInfo
{
InfoViewController *ivc = [self.storyboard instantiateViewControllerWithIdentifier:@"InfoViewController"];
[self presentModalViewController:ivc animated:YES];
}

如果程序达到这一点,则必须是segue的问题。

本周我的按钮也遇到了一些问题。在我的情况下,我的按钮上有一个其他UIView,所以它没有击中选择器。 或者你可以尝试改变:

[infoButton addTarget:self action:@selector(presentInfo) forControlEvents:UIControlEventTouchUpInside];

在:

[infoButton addTarget:self action:@selector(presentInfo) forControlEvents:UIControlEventTouchDown];

同时查看该按钮是否对您的触摸产生了影响。

我希望这会有所帮助

哦或尝试给它一个UITapGestureRecognizer,但这只适用于真正的绝望解决方案,如果没有其他工作......

相关问题