【发布时间】:2013-02-12 18:38:57
【问题描述】:
我已经阅读了很多类似的问题,但我无法弄清楚为什么视图不起作用。我已经花了四个小时来解决这个问题,所以我认为是时候寻求帮助了。
我的主要 VC 代码是一个 UITableView,在 didSelectRowAtIndexPath 中使用了这个方法:
- (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,但没有加载..任何想法都会受到重视。谢谢
更新。服用 cmets 后(谢谢 :))我的代码现在看起来像这样,但仍然没有问题......
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");
【问题讨论】:
-
is 'SubView' 是 'SubViewController' 的 nib 文件吗?
-
您正在创建一个新的导航控制器,而不是使用已经在视图中的那个。您正在创建的导航是不可见的,所以它看起来不像是在推动任何东西
-
@RenoJones:SubView 是笔尖的名称。
-
@ColdLogic。当我简单地使用 self.navigationcontroller 时,我得到了相同的结果。也许如果你添加一个代码sn-p,我可以看看我是否又做了一些愚蠢的事情。
-
哦,显然您需要在进入当前屏幕之前添加导航控制器。您现在所在的屏幕。 (一个带表视图)。在进入此屏幕之前,通过在此屏幕上按下或如果它是第一个控制器,当您在 didfinishlaunching 中将其添加到窗口时,请执行以下操作: UINavigationController *navCont = [[UINavigationController alloc] initWithNibName:@"yourcurrentcontrollerobject" bundle:nil ];然后将 navCont 传递给窗口(如果它是您的第一个控制器),或者将 navCont 传递给将您推到当前屏幕的人。希望我很清楚。干杯。
标签: ios uitableview pushviewcontroller