周家立Zhou Jia Li
周家立Zhou Jia Li

Reputation: 21

I have a storyboard, and I push this. I want to get the name of the control on the storyboard before I launch the controller. how?

I have a storyBoard, and I push this. I want to get the name of the controller on the storyBoard before I launch the controller. how?

if let foodSearchVC = UIStoryboard(name: "Search", bundle: nil).instantiateViewController(withIdentifier: "FoodSearchViewController") as? FoodSearchViewController {
    let searchView = foodSearchVC.searchContainView
    transition = Transition(fromView: seatchContainView, toView: searchView ?? UIView())
    navigationController?.delegate = transition
    foodSearchVC.hidesBottomBarWhenPushed = true
    navigationController?.pushViewController(foodSearchVC, animated: true)
}

This searchView is nil, But I want to get searchView

Upvotes: 1

Views: 52

Answers (1)

Will Jones
Will Jones

Reputation: 2201

You won't be able to access any of the subviews within foodSearchVC because they haven't been created yet; you can only access these after foodSearchVC viewDidLoad.

Off the top of my head I believe you may be able to do what you need to do within the prepareForSegue method, however if you can't you can leverage NSNotificationCenter

However, it appears that you're trying to do custom transitions and what the code you've posted isn't quite how the transitions API works.

This fantastic SO article shows how to do this properly

Upvotes: 2

Related Questions