Reputation: 1
I want a scroll view of my custom viewcontroller
I put some tags and labels in the custom viewcontroller however this error is always showed in the custom viewcontroller's viewdidload func "fatal error: unexpectedly found nil while unwrapping an Optional value"
This is my code of adding viewcontroller to the scroll view
var vcview=eventDetailVCscrollview()
self.addChildViewController(vcview)
self.scrollView.addSubview(vcview.view)
how can i fix it?
Upvotes: 0
Views: 1044
Reputation: 2241
What you see in Xcode as a "viewController" is only a visual representation of a viewController.. All it is, is the owner of a NSView...
Onto that NSView, you drop your scroll-views, other views, labels etc.... and hook them up from there. I'm not sure if you're working on UIKit or AppKit apps but:
1) If Mac (AppKit), take a look at the WWDC 2014 video's introducing "storyboards" 2) If iOS (UIKit), it's probably easier to find a few quick pointers on youtube. Here's one I foind just goggling a moment ago: https://www.youtube.com/watch?v=LHv8MWEe_JA
Just a word of warning though. Storyboards on OS X are a nightmare! If you're new to it, I'd personally go straight for the iOS (AppKit) route as the concepts are different.
Upvotes: 0
Reputation: 131408
The easiest, cleanest way to add another view controller to your view controller is set it up in IB using container views and embed segues.
Select the object library and type "container" into the search bar. You should see a "container view". Drag a container view into the content of your scroll view. Then control-drag from that container view onto the scene of the view controller that you want to host. That will offer to create a segue, and should default to creating an embed segue. Select that option.
You're done.
Upvotes: 0