iOS/iPhone didSelectRowAtIndexPath self.navigationController PushViewController 不起作用

发布于 2024-11-17 11:10:11 字数 2126 浏览 1 评论 0原文

我肯定要失去理智了。我已经编写了我认为相当标准的用法的代码 这里的 didSelectRowAtIndexPath: 方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSInteger row = [indexPath row];
    if (row == 0){
        BuildingDescriptionViewController *buildingDescriptionViewController = [[BuildingDescriptionViewController alloc] initWithNibName:@"BuildingDescriptionViewController" bundle:[NSBundle mainBundle]];
        NSLog(@"self.navigationController0 is %@", self.navigationController ? @"not nil" : @"nil");
        [self.navigationController pushViewController:buildingDescriptionViewController animated:YES];
        [buildingDescriptionViewController release];
    }
    else if (row == 1){
        PostCommentViewController *buildingCommentViewController = [[PostCommentViewController alloc] init];
        NSLog(@"self.navigationController1 is %@", self.navigationController ? @"not nil" : @"nil");
        [self.navigationController pushViewController:buildingCommentViewController animated:YES];
        [buildingCommentViewController release];
    }
}

NSLog 通知 navigationController 不为 nil,但没有其他情况发生。 viewController 都不会出现。事实上,只是发生了 NSLog。我缺少一些深奥的用法吗?我也尝试过 [selfpresentModalViewController:buildingDescriptionViewControlleranimated:YES];但什么也没发生。我确实需要一些帮助。 谢谢。

更新: 根据下面 Saiesh 建议的输出

2011-06-27 18:02:56.370 某事[16331:207]buildingdescriptionviewcontrollerinit 2011-06-27 18:02:56.370 某事[16331:207] ViewControllers 在推送之前:( “建筑配置文件视图控制器:0x7e89680” )

2011-06-27 18:02:56.370 某事[16331:207] 推送后的 ViewControllers:( “BuildingProfileViewController:0x7e89680>”, “建筑描述视图控制器:0x7e73d30” )

2011-06-27 18:03:15.843 某事[16331:207]buildingdescriptionviewcontrollerinit

2011-06-27 18:03:15.844 某事[16331:207] ViewControllers 在推送之前:( “BuildingProfileViewController:0x7e89680”, “建筑描述视图控制器:0x7e73d30” )

2011-06-27 18:03:15.844 某事[16331:207] 推送后的 ViewControllers:( “建筑配置文件视图控制器:0x7e89680” “建筑描述视图控制器:0x7e73d30” “建筑描述视图控制器:0xcc2c8e0” )

I am surely losing my mind. I have coded what I assume to be a fairly standard usage of the
didSelectRowAtIndexPath: method here:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSInteger row = [indexPath row];
    if (row == 0){
        BuildingDescriptionViewController *buildingDescriptionViewController = [[BuildingDescriptionViewController alloc] initWithNibName:@"BuildingDescriptionViewController" bundle:[NSBundle mainBundle]];
        NSLog(@"self.navigationController0 is %@", self.navigationController ? @"not nil" : @"nil");
        [self.navigationController pushViewController:buildingDescriptionViewController animated:YES];
        [buildingDescriptionViewController release];
    }
    else if (row == 1){
        PostCommentViewController *buildingCommentViewController = [[PostCommentViewController alloc] init];
        NSLog(@"self.navigationController1 is %@", self.navigationController ? @"not nil" : @"nil");
        [self.navigationController pushViewController:buildingCommentViewController animated:YES];
        [buildingCommentViewController release];
    }
}

The NSLog informs that the navigationController is NOT nil, but nothing else happens. Neither viewController appears. In fact, just the NSLog occurs. Is there some esoteric usage I am missing? I have also tried [self presentModalViewController:buildingDescriptionViewController animated:YES]; and nothing happened. I could really use some assistance.
Thanks.

UPDATE:
Output per Sailesh's suggestion below

2011-06-27 18:02:56.370 something[16331:207] buildingdecriptionviewcontrollerinit
2011-06-27 18:02:56.370 something[16331:207] ViewControllers before pushing: (
"BuildingProfileViewController: 0x7e89680"
)

2011-06-27 18:02:56.370 something[16331:207] ViewControllers after pushing: (
"BuildingProfileViewController: 0x7e89680>",
"BuildingDescriptionViewController: 0x7e73d30"
)

2011-06-27 18:03:15.843 something[16331:207] buildingdecriptionviewcontrollerinit

2011-06-27 18:03:15.844 something[16331:207] ViewControllers before pushing: (
"BuildingProfileViewController: 0x7e89680",
"BuildingDescriptionViewController: 0x7e73d30"
)

2011-06-27 18:03:15.844 something[16331:207] ViewControllers after pushing: (
"BuildingProfileViewController: 0x7e89680"
"BuildingDescriptionViewController: 0x7e73d30"
"BuildingDescriptionViewController: 0xcc2c8e0"
)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鹤舞 2024-11-24 11:10:11

检查视图控制器是否真的被推入导航堆栈。

要进行检查,请执行以下操作:

NSLog("ViewControllers before pushing: %@", self.navigationController.viewControllers);
[self.navigationController pushViewController:....];
NSLog("ViewControllers after pushing: %@", self.navigationController.viewControllers);

控制台中的输出将是 viewController 的一些地址,但您至少会知道推送 viewController 之前和之后导航堆栈中的 viewController 的数量。我想,如果它们被推动,那么问题一定出在代码的其他部分。

请回复输出。

Check if the view controller is really being pushed into the navigation stack.

To check, do this:

NSLog("ViewControllers before pushing: %@", self.navigationController.viewControllers);
[self.navigationController pushViewController:....];
NSLog("ViewControllers after pushing: %@", self.navigationController.viewControllers);

The output in the console will be some adresses of the viewControllers, but you will at least know the number of viewControllers in the navigation stack before and after pushing viewController. If they ARE getting pushed, then the problem must be in some other part of your code, I suppose.

Please reply with the output.

梦中楼上月下 2024-11-24 11:10:11

我终于找到了问题所在。我对 self.navigationController 不是 NIL 感到困惑。问题是 tableView 已被添加为子视图。我通过将其 viewController 推送到导航堆栈来修复它。感谢所有回复的人。

I finally found the problem. I was confused by the fact that the self.navigationController wasn't NIL. The issue was that the tableView had been added as a subview. I fixed it by pushing its viewController onto the navigation stack. Thanks to everyone that replied.

花之痕靓丽 2024-11-24 11:10:11

我刚刚通过调用任何视图方法或属性解决了我的问题。

childController = [[YouTubeLaunch alloc] initWithNibName:@"YouTubeView" bundle:nil];
        childController.view.userInteractionEnabled = YES;

过去三天我也遇到了同样的问题。虽然 viewController 正在添加,但只有 RootViewController 出现,而​​不是 YouTubeEmbedPlayer

2011-06-27 19:53:17.677 [1263:207] ViewControllers 推送前:( "", "", "", "" ) 2011-06-27 19:53:22.496 [ 1263:207] 推送前的 ViewControllers:(“”、“”、“”、“”、“”)

I just resolved my issue by calling any view method or property.

childController = [[YouTubeLaunch alloc] initWithNibName:@"YouTubeView" bundle:nil];
        childController.view.userInteractionEnabled = YES;

I also had the same issue for the last 3 days. Although the viewController is getting added but only RootViewController is coming up but not YouTubeEmbedPlayer .

2011-06-27 19:53:17.677 [1263:207] ViewControllers before pushing: ( "", "", "", "" ) 2011-06-27 19:53:22.496 [1263:207] ViewControllers before pushing: ( "", "", "", "", "" )

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文