I have been struggling with this issue for days and cannot get it to work. Read multiple SO posts (this, this, this, this, this and this). Asked my friend Google, helped to understand the problem but not to solve it yet.
In the first version of my iOS app (Swift2 and XCode7) I use a UITableViewController and UINavigationViewController to load new content from a different UIStoryboard. This all works fine. For the second version of this app I want to implement a UISplitViewController and now I am getting the error:
*** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'adding a root view controller as a child of view controller:
I understand the hint, but cannot solve it in a way that works either in portrait and landscape mode. Moreover, the sort of solution I had did not use the UINavigationController in the landscape orientation.
I created a test project to track down this error, hoping to solve it.
This is the code that generates the error:
let storyboard = UIStoryboard(name: "ThirdScreen", bundle: nil)
let controller = storyboard.instantiateInitialViewController() as! ThirdDetailViewController
controller.title = "Miracle!"
splitViewController?.showDetailViewController(controller, sender: nil)
The full code of this test project is available from GitHub.
How can I make this work?
Thanks a lot!
I found a solution, the trick is to remove the segue and use a storyboard reference like this:
For testing and teaching purposes, I created a complete test project which is available from GitHub. This demonstrates the use of multiple storyboards for the detail view.
Update Nov 28: this solution works but requires iOS 9. It is perfectly possible to use another UIViewController as a DetailViewController (meaning the template can be used) as long as you remove the segue, implement tableView: didSelectRowAtIndexPath and use the code from the example. In the latter case, it also works on iOS 8.
Related
There are empty spaces on top of the View Controller. The UI was correct before updating to the latest Xcode Version. After updating to the latest version i got this behaviour. Some of the View Controller was correct updated butnot all. Check the Image to understand my problem (The View controller on the right side has an empty gray space.
If you compile it you see the same behaviour on the simulator (on all devices).
Looks like a second application in the background when you start the app.
I hope someone can help me.
Thanks!
you should config your ViewController when presenting like that:
yourViewController.modalPresentationStyle = UIModalPresentationFullScreen;
[self yourViewController animated:YES completion:NULL];
Try to set, parent ViewController's (Edit MemberVC, I assume) Top Bar property to None.
Just got this error in our error logging system, been searching hi and low and can't seem to find any solution. Any help is appreciated. Here is the stacktrace.
May be in your XCODE log you might have encountered this message
"Presenting view controllers on detached view controllers is
discouraged ".
If yes then then try
[self.view.window.rootViewController presentViewController:myVC];
if this fails then make sure you call presentViewController:myVC on immediate presenting ViewController i.e. in your case what I see from trace - CalendarEventDetailViewController.
If that too fail then go backward - from where you are invoking VC which in turn use presentViewController, in iOS8 presentation layer has changed specially WRT UIAlert/UIActionSheet, and UIPopovers,
if you are using any of these, create UIAlertController as a separate code track for iOS8 and use presentViewController:myVC on presenting ViewController.
I was facing similar issue where presentViewController: not working at all or disrupting presenting VC contents, in some situations dismissViewController was crashing. Using this approach I could fix it.
I often make use of views in interface builder that live outside of the viewcontroller hierarchy (see screen grab below for simple example).
Before upgrading to Xcode5 I could get this view to appear on the storyboard by writing an IBAction outlet and dragging a connection from the code to the view in the storyboard.
If you paused over the button for a moment it would flash and then open up as a view on the storyboard that is then a lot easier to work with.
Since upgrading this function no longer seems available. Has anyone found out how to get these views to appear on the storyboard?
Edit:
Using the temporary viewcontroller as described in this answer seems one approach, although fiddly since you need to move the UIView stack between viewcontrollers each time you want to edit the layout. Using a separate XIB is starting to seem like the sanest approach.
https://stackoverflow.com/a/13713385/1060154
Finally, we get this back in Xcode 7.
Hallelu!
I'm developing an iPad app that supposed to output a website to another view, but when the second view loads, it comes up null. I'm using storyboard to link a button to push the web view controller and load the webpage into that view. The code works fine in the first view (indicated by NSLog), but NSURL never makes it to the second view (NSLog "Null").
Code in IBAction on first view:
self.sanctuaryWebViewController = [[SanctuaryWebViewController alloc]init];
self.sanctuaryWebViewController.URL = [NSURL URLWithString:#"http://www.website.org"];
Code in ViewDidLoad Second View Controller:
NSURLRequest *requestObject = [NSURLRequest requestWithURL:URL];
[webView loadRequest:requestObject];
I have done this in an Iphone app fine declaring a nav delegate to push the view, but not sure if using storyboard or splitview has anything to do with the problem. I spent hours searching for help and tried several different ways to code, but no go. I think I'm close, but not quite there. Using Xcode 4.4 and running on OS 10.8; IOS 5.1
Thanks for any suggestions
Can you show us more of the second view controller's code? I'm assuming you are using ARC? I assume you mean the result is coming up nil rather than NSNull (there is a difference)? Have you connected the webView in the second view controller to the UIWebView in the Storyboard/IB?
Good luck!
I was declaring UIWebview twice. "webview" and "_webview". I removed the instant variable declared in .h and kept the property. Made sure "_webview" was used. Also, Since I linked a segue to a button, I got rid of the IBAction method and replaced it with the prepareForSegue method, which calls the segue. Really had know idea what I was doing using storyboard. I knew about the segue methods, but did not realize they are not linked to the button like IBAction methods. They seem to be used in similar way as calling xib files, but calling segues.
I find it very convenient to use storyboards, especially to have (and show) an overview of the application.
However, I also find it very annoying to replicate the same code and views without the possibility to keep at least a reusable library of the most common xibs.
This is especially true with UITableView and its cell.
Did some of you have had any idea or best practice to share for dealing with this issue?
I was just looking at this yesterday, and it doesn't appear to be possible just yet. I've decided to go for the good old nib in case I want to be able to reuse a view. You can still use them while your main UI is defined in a storyboard using
UIView *view = [[NSBundle mainbundle] loadNibNamed:#"Nibfile" owner:self options:nil];
I tried this for about two weeks when finally discovery that you have to define if you will work with storyboard or xib files. They aren't going to work together.
I think that is sad too, but until the moment, there's nothing to do about it. The storyboard don't call your xib files and the segues will not work too.
According to several other posts - search storyboard and xib - people are currently using xibs and storyboards together, where xibs can be used to handle re-usable views. When you create a new file -> iOS -> View or Window, xcode creates a xib for you.