[英]Pushing viewController from a tableview that is inside a viewController not working
[英]iOS Pushing a ViewController not working
我已經閱讀了很多類似的問題,我無法弄清楚為什么這個觀點不起作用..我已經花了四個小時就這個,所以我覺得是時候尋求幫助了。
我的主要VC代碼是在didSelectRowAtIndexPath上使用此方法的UITableView:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"%s", __FUNCTION__);
svc = [[SubViewController alloc] initWithNibName:@"SubView" bundle:nil];
//UINavigationController *nc = [[UINavigationController alloc] init];
switch (indexPath.section) {
case 0 :
switch (indexPath.row) {
case 0 :
NSLog(@"0");
svc.label.text = @"Item";
break;
case 1:
NSLog(@"1");
svc.label.text = @"Category";
break;
}
break;
NSLog(@"2");
case 1 : svc.title = @"Second Cell"; break;
case 2 : svc.title = @"Third Cell"; break;
case 3 : svc.title = @"Image"; break;
case 4 : svc.title = @"Notes"; break;
NSLog(@"3");
break;
}
NSLog(@"4");
//svc = [[SubViewController alloc] init];
NSLog(@"svc is %@", svc);
UINavigationController *nc = [[UINavigationController alloc] initWithNibName:@"SubView" bundle:nil];
//initWithRootViewController:svc];
[nc pushViewController:svc animated:YES];
NSLog(@"self.navigation is as %@",nc);
NSLog(@"5");
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
你也可以看到我嘗試過的東西。 輸出日志顯示:
2013-02-12 13:32:22.858 CollapsableTableView[35122:c07] -[ViewController tableView:didSelectRowAtIndexPath:]
2013-02-12 13:32:22.859 CollapsableTableView[35122:c07] -[SubViewController initWithNibName:bundle:]
2013-02-12 13:32:22.860 CollapsableTableView[35122:c07] wtf
2013-02-12 13:32:22.860 CollapsableTableView[35122:c07] 0
2013-02-12 13:32:22.860 CollapsableTableView[35122:c07] 4
2013-02-12 13:32:22.861 CollapsableTableView[35122:c07] svc is <SubViewController: 0x10363070>
2013-02-12 13:32:22.863 CollapsableTableView[35122:c07] self.navigation is as <UINavigationController: 0x101608b0>
2013-02-12 13:32:22.863 CollapsableTableView[35122:c07] 5
所以SubView正在被發現,但沒有加載..任何想法都會受到重視。 謝謝
UPDATE。 在評論之后(感謝:))我的代碼現在看起來像這樣,但仍然是虛無...
svc = [[SubViewController alloc] initWithNibName:@"SubView" bundle:nil];
UINavigationController *nc = self.navigationController;
switch (indexPath.section) {
case 0 :
switch (indexPath.row) {
case 0 :
NSLog(@"0");
svc.label.text = @"Item";
break;
case 1:
NSLog(@"1");
svc.label.text = @"Category";
break;
}
break;
NSLog(@"2");
case 1 : svc.title = @"Second Cell"; break;
case 2 : svc.title = @"Third Cell"; break;
case 3 : svc.title = @"Image"; break;
case 4 : svc.title = @"Notes"; break;
NSLog(@"3");
break;
}
NSLog(@"4");
//svc = [[SubViewController alloc] init];
NSLog(@"svc is %@", svc);
[nc pushViewController:svc animated:YES];
//pushViewController:svc animated:YES];
NSLog(@"self.navigation is %@",nc);
NSLog(@"5");
UINavigationController *nc = [[UINavigationController alloc] initWithNibName:@"SubView" bundle:nil];
用以下內容代替:
UINavigationController *nc = self.navigationController;
您正在創建一個全新的UINavigationController
。 你需要使用你擁有的那個並推動它。
注意
即使您正在創建一個新的UINavigationController
,也不會使用視圖控制器nib。 您將使用您評論的代碼為新的UINavigationController
設置rootViewController
。
在創建此視圖之前添加導航控制器(APP DELEGATE)等。 然后將此視圖作為導航控制器的根目錄。
最后。 self.navigationController pushViewController:(UIViewController*) animated:(BOOL)
我認為這樣做會self.navigationController pushViewController:(UIViewController*) animated:(BOOL)
。 如果您不確定如何添加導航控制器,則使用根視圖控制器搜索導航控制器的init。
但是,如果你的觀點是在這里添加一個新的視圖控制器那么你是正確的,只是忘了將子視圖添加到主視圖中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.