[英]ios change view on button click
我是ios开发的新手,我知道非常简单,我想更改按钮视图单击这是我的代码,我创建了Tabbed Application,storyboard流是
TabView控制器->导航控制器-> HomeViewController->导航控制器-> ShopViewController
程式码片段:
@implementation HomeViewController
@synthesize users;
- (IBAction)shopButton:(id)sender {
NSLog(@"hi sachin");
NSLog(@"INSIDE Shops");
ShopViewController *cvc = [[ShopViewController alloc]initWithNibName:@"ShopViewController" bundle:nil];
[self.navigationController pushViewController:cvc animated:YES];
}
它显示了这样的错误:
Pacific1[2556:70b] hi sachin
2014-02-25 16:34:49.374 Pacific1[2556:70b] INSIDE Shops
2014-02-25 16:34:49.632 Pacific1[2556:70b] *** Terminating app due to uncaught
exception 'NSInternalInconsistencyException', reason: 'Could not load
NIB in bundle: 'NSBundle (loaded)' with name 'ShopViewController''
您的“ ShopViewController” xib不存在。 看到:
Terminating app due to uncaught
exception 'NSInternalInconsistencyException', reason: 'Could not load
NIB in bundle: 'NSBundle (loaded)' with name 'ShopViewController''
“无法在捆绑包中加载NIB”
如果使用情节提要,则可能需要实例化视图,如下所示:
ShopViewController *cvc = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"ShopViewController"];
并非100%,但是其他人也许可以为您指出正确的方向,因为我不使用情节提要。
如果使用情节提要,则应使用instantiateViewControllerWithIdentifier
方法实例化视图控制器。
例:
ShopViewController *viewController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"ShopViewController"];
确保identifier
正确。 它位于Interface Builder
的Identity Inspector
选项卡下。 这就是Storyboard ID
。 您可以为其指定任何唯一的名称。 还要确保情节提要名称与情节提要的名称匹配(无文件扩展名)。
然后:
[self.navigationController pushViewController:viewController animated:YES];
ShopViewController *cvc = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"youstoryboardID"];
如果仍然没有导航,则在故事板中选择MainViewcontroller
,然后单击Editor > Embed In在其中,选择NavigationController
。
我认为它将起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.