我有这行代码:
[UIStoryboard storyboardWithName:(NSString *) bundle (NSBundle *)];和一个故事板文件。我应该在哪里实际插入控制器的名称,在哪里可以找到捆绑包?
这是一个愚蠢的问题,但我想不出来
发布于 2012-09-21 23:47:20
一切都很简单!
代码如下:
UIStoryboard *storyboard =
[UIStoryboard storyboardWithName:@"MainStoryboard"
bundle:[NSBundle mainBundle]];其中is @"Main Storyboard"是.storyboard文件的名称。捆绑包是包含.storyboard文件的捆绑包,通常是应用程序的主捆绑包。
例如,如果您希望访问某些UIViewControllers,目的是将其推送到UINavigationController的堆栈中,则必须执行以下操作:
UIViewController *yourViewController =
[storyboard instantiateViewControllerWithIdentifier:@"viewControllerIdentifier"];可以在Xcode的身份检查器中将标识符设置为您的UIViewController!
希望能对你有所帮助!
发布于 2012-09-21 23:47:18
name参数是您的文件的名称(不带扩展名)。
bundle通常是应用程序的主包。通常,可以传递nil,以便运行库在默认情况下在主包中搜索情节提要文件(与传递[NSBundle mainBundle]时相同)。实际上,在iOS应用程序中通常只有一个包,它是代表IPA包的主包,因此nil是此参数的通用值)
例如,如果您有一个名为MyStory.storyboard的情节提要,您会这样写:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MyStory" bundle:nil];实际上,所有这些都在in the Apple documentation for this method中得到了解释。
storyboardWithName:捆绑包:
为指定的情节提要资源文件创建并返回情节提要对象。
+ (UIStoryboard *)storyboardWithName:(NSString *)name bundle:(NSBundle *)storyboardBundleOrNil
参数
name:不带文件扩展名的情节提要资源文件的名称。如果此参数为包含情节提要文件及其相关资源的包的nil.storyboardBundleOrNil:,则此方法将引发异常。如果指定为nil,此方法将在当前application.的主包中查找
发布于 2015-08-21 18:49:19
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];https://stackoverflow.com/questions/12533777
复制相似问题