我在故事板中有一个名为" X"的视图控制器A.在它我有一个按钮。点击它我正在检查API的成功响应,之后我需要导航到故事板中的视图控制器B" B"
我正在使用代码:
let loginstoryboard = UIStoryboard(name: "Login", bundle: nil)
let loginController = loginstoryboard.instantiateViewController(withIdentifier: "login") as? LoginViewController
self.navigationController?.pushViewController(loginController!, animated: true)
所以它不适合我。有什么问题?
答案 0 :(得分:2)
请按照以下步骤操作。
请检查StoryboardID的样本图像
示例代码
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:"YourStoryBoardName" bundle:nil];
UIViewController *loginViewController = [storyBoard instantiateViewControllerWithIdentifier:"LoginViewController"];
// If Login View Controller is not a Navigation Controller then you need to create Navigation Controller
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:loginViewController];
[self.navigationController pushViewController:viewController animated:true];
答案 1 :(得分:0)
您可以使用其storyboard id在以下编程方式下创建故事板的引用,然后实例化viewcontroller。
let loginstoryboard = UIStoryboard(name: "Login", bundle: nil)
在故事板中 您甚至可以在外部故事板中引用视图控制器。请参阅@bshirley ans以获取详细说明。