having a bit of a problem here, so I was trying to cal a function of which it will change the height constraint constant, but it gives me an error :
"NSLayoutConstraint: Found nil while unwrapping optional Value"
Another catch is I can change the constant from the ViewDidLoad() function without any errors, while calling the function from another controller gives me the error.
I tried to clean the project, delete the outlet and re-outlet it again. No luck.
Hope you can help me, thanks!
MainController
var bottomContainerCon: CGFloat = 80
@IBOutlet var bottomContainerHeight: NSLayoutConstraint!
override func viewDidLoad() {
super.viewDidLoad()
bottomContainerHeight.constant = bottomContainerCon
}
func changeHeight() {
bottomContainerHeight.constant = self.bottomContainerCon
self.view.layoutIfNeeded()
}
PagerController
func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = self.storyboard?.instantiateViewController(withIdentifier: "MainNeedPage") as! NeedDetailsController
let currentIndex = pages.index(of: previousViewControllers.first!)!
let nextIndex = abs((currentIndex + 1) % pages.count)
if(nextIndex == 0) {
vc.changeHeight(value:80)
} else {
vc.changeHeight(value:250)
}
override func viewDidLayoutSubviews() {
self.bottomContainerHeight.constant = self.bottomContainerCon
self.view.layoutIfNeeded()
}
Here's the storyboard Storyboard