UIStoryboard 从另一个 UIStoryboard 打开
UIStoryboard open from another UIStoryboard
我在从第二个调用一个 UIStoryboard 时遇到问题。我的第一个故事板 - 主要,第二个 - 管理。当您单击 UIButton 时,不会发生任何操作。我的源代码:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Management" bundle:[NSBundle mainBundle]];
UIViewController *yourViewController = [storyboard instantiateViewControllerWithIdentifier:@"Management"];
[self.navigationController pushViewController:yourViewController animated:YES];
这里可能有很多原因。
1. 您可能忘记为您的 UIButton 设置 IBAction 插座
2.故事板名称可能与您在代码中指定的名称不匹配
3. [故事板实例化ViewControllerWithIdentifier:@"Management"];您确定为此控制器指定了相同的 Storyboard ID 吗?
4. 为了检查所有这些建议,只需在代码的第一行设置断点并尝试重现这种情况就足够了。
该代码中可能会发生许多错误。
首先要确定你的action是连接好的,在你的action中打断点看是否被调用。
其次确保故事板名称正确,在故事板后放置一个断点并检查它是否不为零(po storyboard
在调试控制台中)。
其次确保 "Management.storyboard" 有一个 ViewController 和标识符 "Management"。所以在你的 ViewController 之后放置一个断点来检查它是否为 nil (po yourViewController
in the debugger console).
最后确保您执行操作的视图控制器位于导航控制器内。因此,检查 self.navigationController 是否为 nil(在操作代码中停止后在调试器控制台中显示 po self.navigationController
)
需要用这个替换旧代码。
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Management" bundle:[NSBundle mainBundle]];
UIViewController *yourViewController = [storyboard instantiateViewControllerWithIdentifier:@"ManagementIDS"];
[self presentViewController:yourViewController animated:YES completion:nil];
如果您更喜欢在界面生成器中而不是在代码中进行:
您现在可以在界面生成器中创建故事板引用。这意味着您可以 link 来自另一个故事板的故事板。目标必须是 ios9.
检查19:00
https://developer.apple.com/videos/wwdc/2015/?id=407
我在从第二个调用一个 UIStoryboard 时遇到问题。我的第一个故事板 - 主要,第二个 - 管理。当您单击 UIButton 时,不会发生任何操作。我的源代码:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Management" bundle:[NSBundle mainBundle]];
UIViewController *yourViewController = [storyboard instantiateViewControllerWithIdentifier:@"Management"];
[self.navigationController pushViewController:yourViewController animated:YES];
这里可能有很多原因。 1. 您可能忘记为您的 UIButton 设置 IBAction 插座 2.故事板名称可能与您在代码中指定的名称不匹配 3. [故事板实例化ViewControllerWithIdentifier:@"Management"];您确定为此控制器指定了相同的 Storyboard ID 吗? 4. 为了检查所有这些建议,只需在代码的第一行设置断点并尝试重现这种情况就足够了。
该代码中可能会发生许多错误。
首先要确定你的action是连接好的,在你的action中打断点看是否被调用。
其次确保故事板名称正确,在故事板后放置一个断点并检查它是否不为零(po storyboard
在调试控制台中)。
其次确保 "Management.storyboard" 有一个 ViewController 和标识符 "Management"。所以在你的 ViewController 之后放置一个断点来检查它是否为 nil (po yourViewController
in the debugger console).
最后确保您执行操作的视图控制器位于导航控制器内。因此,检查 self.navigationController 是否为 nil(在操作代码中停止后在调试器控制台中显示 po self.navigationController
)
需要用这个替换旧代码。
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Management" bundle:[NSBundle mainBundle]];
UIViewController *yourViewController = [storyboard instantiateViewControllerWithIdentifier:@"ManagementIDS"];
[self presentViewController:yourViewController animated:YES completion:nil];
如果您更喜欢在界面生成器中而不是在代码中进行:
您现在可以在界面生成器中创建故事板引用。这意味着您可以 link 来自另一个故事板的故事板。目标必须是 ios9.
检查19:00 https://developer.apple.com/videos/wwdc/2015/?id=407