我想從UIScrollView子視圖呈現視圖控制器。 我試過使用AppDelegate window.rootViewController presentViewController:但是這給了我「視圖不在層次結構!」錯誤。 我想避免使用addSubview,因爲它打破了MVC,似乎刪除了控制器的功能(按鈕停止工作)。 當我使用期望的presentViewController方法時,我得到「沒有可見的@interface爲」InititalScrollViewSubview「聲明選擇器」presentViewController:animated:completion:「,我認爲這意味着我的initialScrollViewSubview試圖使用presentViewController,但presentViewController必須來自。一個UIViewController的UIScrollView是沒有presentViewController方法從UIScrollView子視圖呈現故事板UIViewController
我的代碼是一樣的東西:
-(void)setupTouchIDButtonTapped: (id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"newViewController" bundle:nil];
NewViewController *myNewViewController = [storyboard instantiateViewControllerWithIdentifier:@"myNewVC"];
//第一件事我想:
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate.window.rootViewController presentViewController:NewViewController animated:YES completion:nil];
//第二件事情,我想我試圖
[self addSubview:NewViewController.view];
//第三件事:
[self presentViewController:NewViewController animated:YES completion:nil];
}
的InitialScrollViewSubview必須保持它的方式。理想情況下,我會重構一切,以便InitialScrollViewSubview是另一個UIViewController,但我爲一家大公司工作,而且該應用程序太大了:) 任何建議都非常感謝!
謝謝!
謝謝! 我試過了,使用[self addSubview:NewViewController.vew]; 視圖出現,但我所有的按鈕停止工作。這是因爲它失去了「控制器」功能,因爲它現在只是scrollView視圖的一部分? –
scrollview可能是註冊爲接收事件的主視圖,請嘗試在viewcontroller.view上啓用userInteractionenabled。你也可以嘗試這裏的提示:http://stackoverflow.com/questions/4629499/how-to-steal-touches-from-uiscrollview – Scriptable
這可能是你需要的解決方案http://stackoverflow.com/questions/16649639/UIButton的 - 不 - 不工作時,其功能於UIScrollView中 – Scriptable