Более конкретно,
Скажем, у меня есть UIViewController
A, когда я UIViewController
button
в A, которая создается кодом, я хотел бы отобразить другой UIViewController
B, где B спроектирован в storyboard
. Это можно сделать с помощью кодирования, но не используя связи между view controllers
в storyboard
. Благодарю.
Абсолютно,
Убедитесь, что вы добавили storyBoardIdentifier в ViewController B.
Наконец, в вашем ViewController A:
let YourStoryBoard = UIStoryboard(name: "YourStoryBoard", bundle: nil)
let vc = YourStoryBoard.instantiateViewController(withIdentifier: "VCB_StoryBoard_Identifier") as! ViewControllerB
Если ваш ViewController имеет встроенный в него UINavigationController,
self.navigationController?.pushViewController(vc, animated: true)
Осталось представить ViewController B из ViewController A
self.present(vc, animated: true, completion: nil)
РЕДАКТИРОВАТЬ:
Задайте свой идентификатор раскадровки, как показано на рисунке ниже
Свяжите свой класс ViewControllerB с VC раскадровки, установив класс ViewController. Как показано ниже.
Вы должны создать новый класс касания cocoa → UIViewController → "ViewContollerB"
Добавьте имя в раскадровку в представление и чем вы можете это сделать:
let storyboard = UIStoryboard (имя: "YourStoryBoard", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "VCB_StoryBoard_Identifier") как! ViewContollerB
Попробуй это:
При нажатии кнопки в UIViewController
A
,
func onTapButton()
{
let controller = UIStoryboard.init(name: "YOUR_STORYBOARD_NAME", bundle: nil).instantiateViewController(withIdentifier: "ViewControllerBIdentifier") as! ViewControllerB
self.present(controller, animated: true, completion: nil)
}
Вот,
ViewControllerBIdentifier
: StoryboardID
соответствующий UIViewController
B
ViewControllerB
: class
соответствующий UIViewController
B