ios更改按钮单击视图

时间:2014-02-25 11:34:55

标签: ios viewcontroller

我是ios开发的新手我知道非常简单,我想改变点击按钮的视图 这是我创建Tabbed应用程序的代码,故事板流程是

  

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''

3 个答案:

答案 0 :(得分:0)

您的“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%,但其他人可能会指出你正确的方向,因为我不使用故事板。

答案 1 :(得分:0)

如果您使用的是故事板,则应使用 instantiateViewControllerWithIdentifier 方法实例化视图控制器。

示例:

ShopViewController *viewController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"ShopViewController"];

确保 identifier 正确无误。它位于Identity Inspector的{​​{1}}标签下。它被称为Interface Builder。您可以为其指定任何您想要的唯一名称。还要确保故事板名称与故事板的名称相匹配(没有文件扩展名)。

然后:

Storyboard ID

答案 2 :(得分:0)

ShopViewController *cvc = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"youstoryboardID"];

如果仍然如此,请不要在故事板中导航,选择MainViewcontroller并点击编辑> 嵌入,然后选择NavigationController

我认为它会奏效。

相关问题