I'm adding a view to the window with this objective-c code:
// Main Storyboard
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
// View controller with the view to add
UIViewController *vc = [mainStoryBoard instantiateViewControllerWithIdentifier:@"SomeViewController"];
// Find the topmost window
UIWindow *topWindow = [[[UIApplication sharedApplication].windows sortedArrayUsingComparator:^NSComparisonResult(UIWindow *win1, UIWindow *win2) {
return win1.windowLevel < win2.windowLevel || !win1.isOpaque;
}] lastObject];
// Add the view to the window
[topWindow addSubview:vc.view];
This works fine and so does this Swift method I use in SomeViewController
to leave the view:
// Get topmost window (Should be UIWindow)
let topWindow = UIApplication.shared.windows.sorted {
(win1, win2) in
return win1.windowLevel < win2.windowLevel || !win1.isOpaque
}.last
// Force view to prepare to disappear
self.viewWillDisappear(true)
// Send the view to the back
topWindow?.sendSubviewToBack(view)
This is the structure of my views after the objective-c code runs. The selected view is the one that got added:
The issue is none of the buttons in the new view work so I can't trigger the above close method. I've tried both buttons added with the storyboard and programmatically added buttons. Visually the buttons react when tapped but they won't trigger anything.