[英]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.