Dad*_*See 75 user-interface ios ios5 xcode4.2 uistoryboard
我的目标是创建一个选项卡式应用程序,然后每个选项卡的视图都在不同的故事板中构建.

我的主板是一个标签视图.
然后我创建了一个带有2个View Controller的辅助故事板(故事板#2).第一个视图控制器(也标记为初始)有一个按钮,并且segue(模态)有第二个视图.
我设法通过从故事板#2继承和覆盖loadView来加载视图.

这是模拟器输出.

点击"点击我"按钮,我得到一个EXC_BAD_ACCESS.segue不起作用,似乎第二个故事板没有被完全加载.
有没有人试图这样做,并让它工作?有来自SkillMaster.net的youtube视频,但他没有证明segue是否在次要故事板下工作.视频在这里:http://youtu.be/D4_twoYvB4M
感谢您的任何意见和帮助!
截图:
pch*_*10k 44
OP编辑了他的问题,包括答案:
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"HelpStoryboard" bundle:nil];
UIViewController* initialHelpView = [storyboard instantiateInitialViewController];
initialHelpView.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:initialHelpView animated:YES];
Run Code Online (Sandbox Code Playgroud)
当然,你从中调用它是有意义的,因为你可能有2个故事板和它们的视图堆栈在内存中.因此,如果您从其他故事板的视图控制器之外调用此代码,那么最好.
vok*_*lam 19
我研究了Rhubarb建议的RBStoryboardLink方法.此实现替换视图控制器的看起来很奇怪的属性.我相信我找到了避免这种情况的方法.这是演示项目.
导航控制器可以将引用的视图控制器设置为根.这种视图控制器的实现可能如下所示:
@interface ExternNavigationController : UINavigationController
@property (strong, nonatomic) NSString *storyboardName;
@property (strong, nonatomic) NSString *sceneIdentifier;
@end
@implementation ExternNavigationController
- (void)awakeFromNib
{
NSAssert(self.storyboardName, @"storyboardName is required");
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:self.storyboardName bundle:nil];
UIViewController *vc = self.sceneIdentifier
? [storyboard instantiateViewControllerWithIdentifier:self.sceneIdentifier]
: [storyboard instantiateInitialViewController];
self.viewControllers = @[vc];
}
@end
Run Code Online (Sandbox Code Playgroud)
如果要推送外部故事板中定义的视图控制器,问题就会开始.复制属性时就是这种情况.取而代之的是,我们可以实现一个自定义segue,它将伪造的目标控制器替换为来自外部故事板的真实目标控制器.
@interface ExternStoryboardSegue : UIStoryboardSegue
@end
@implementation ExternStoryboardSegue
- (id)initWithIdentifier:(NSString *)identifier source:(UIViewController *)source destination:(ExternViewController *)destination
{
NSAssert(destination.storyboardName, @"storyboardName is required");
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:destination.storyboardName bundle:nil];
UIViewController *vc = destination.sceneIdentifier
? [storyboard instantiateViewControllerWithIdentifier:destination.sceneIdentifier]
: [storyboard instantiateInitialViewController];
return [super initWithIdentifier:identifier source:source destination:vc];
}
- (void)perform
{
[[self.sourceViewController navigationController] pushViewController:self.destinationViewController animated:YES];
}
@end
Run Code Online (Sandbox Code Playgroud)
ExternViewController用作占位符,包含替换属性(storyboardName和sceneIdentifier)所需.
@interface ExternViewController : UIViewController
@property (strong, nonatomic) NSString *storyboardName;
@property (strong, nonatomic) NSString *sceneIdentifier;
@end
@implementation ExternViewController
@end
Run Code Online (Sandbox Code Playgroud)
我们需要为占位符视图控制器设置这些属性和自定义类.并且还将视图控制器与ExternStoryboardSegue链接.

Joa*_*eie 16
从我的一个XIB文件导航到GUI的一个更复杂的部分,对于这部分我使用的是Storyboard.因此,我的XIB中的按钮将导航到故事板.我的代码是:
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MyStoryboardIdentifier" bundle:nil];
UIViewController* myStoryBoardInitialViewController = [storyboard instantiateInitialViewController];
[self.navigationController pushViewController:myStoryBoardInitialViewController animated:YES];
Run Code Online (Sandbox Code Playgroud)
这将成功将我的StoryBoard推送到视图上.上面的代码是从"Touch Up Inside"按钮调用的.
Apple的文档说你可能有多个故事板.不幸的是,他们没有详细说明如何做到这一点.正如您所知,Interface Builder不会帮助您,因此您必须在代码中执行此操作.它的工作方式与加载XIB非常相似:
[UIStoryboard storyboardWithName:@”MyNewStoryboard” bundle:myBundle]
Run Code Online (Sandbox Code Playgroud)
话虽如此,如果你没有像你在评论中所说的那样"想要一个大/臃肿的故事板",那么XIB真的是要走的路."重大"就是好处:风险投资之间的所有过渡都在一个地方进行.拥有多个故事板确实可以通过您的应用程序支持多个不同且不相关的流:例如,一个故事板用于复杂的配置流,另一个用于主用户流.
| 归档时间: |
|
| 查看次数: |
65890 次 |
| 最近记录: |