所以我整个晚上都在试图解决我的问题,即单击位于 UIViewController 中的按钮不会触发 IBAction。
我正在使用故事板构建我的应用程序,我的主要 ViewController 是一个 TabBarViewController。所述 TabBarViewController 的其中一项是,让我们称之为MainViewController。
后面MainViewController是BackgroundViewController仅包含相机预览而没有其他内容的内容。
BackgroundViewController在里面添加MainViewController如下:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
BackgrondViewController *bckgController = (BackgrondViewController *)[storyboard instantiateViewControllerWithIdentifier:@"background"];
[self.view addSubview:bckgController.view];
[self.view sendSubviewToBack:bckgController.view];
Run Code Online (Sandbox Code Playgroud)
到目前为止一切正常,我之所以提到它,是因为这可能是相关的。
现在我想将另一个 ViewController 添加到MainViewController,这次是在顶部。让我们将顶视图控制器称为TopViewController.
所以首先我像这样设置它:
TopViewController *topController = (TopViewController *)[storyboard instantiateViewControllerWithIdentifier:@"top"];
topController.view.backgroundColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)
我添加了 clearColor 因为在我的应用程序中需要它并且它确认这没有任何改变(相信我,我试过)。
好的,现在我添加新创建的视图如下(我们还在里面 MainViewController)
[self.view addSubview:topController.view];
[self.view bringSubviewToFront:topController.view];
Run Code Online (Sandbox Code Playgroud)
事实上,它确实显示透明视图,中间只有一个按钮。
无论我尝试什么,我都无法让按钮调用其 IBAction 方法。
TopViewController实际上是在MainViewController视图之上,我通过获取 …