iOS / iPhone didSelectRowAtIndexPath self.navigationController pushViewController无法正常工作

时间:2011-06-27 10:31:37

标签: iphone objective-c ios cocoa-touch uinavigationcontroller

我肯定会失去理智。我编码了我认为是相当标准的用法 这里有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发生。我缺少一些深奥的用法吗?我也试过[self presentModalViewController:buildingDescriptionViewController animated:YES];什么都没发生我真的可以使用一些帮助。 感谢。

更新: 按照Sailesh的建议输出

  

2011-06-27 18:02:56.370 something [16331:207] buildingdecriptionviewcontrollerinit   2011-06-27 18:02:56.370 [16331:207]推送前的ViewControllers :(     “BuildingProfileViewController:0x7e89680”   )

     

2011-06-27 18:02:56.370 [16331:207]推送后的ViewControllers :(      “BuildingProfileViewController:0x7e89680>”,      “BuildingDescriptionViewController:0x7e73d30”   )

     

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

     

2011-06-27 18:03:15.844 [16331:207]推送前的ViewControllers :(      “BuildingProfileViewController:0x7e89680”,      “BuildingDescriptionViewController:0x7e73d30”   )

     

2011-06-27 18:03:15.844 [16331:207]推送后的ViewControllers :(      “BuildingProfileViewController:0x7e89680”      “BuildingDescriptionViewController:0x7e73d30”      “BuildingDescriptionViewController:0xcc2c8e0”   )

3 个答案:

答案 0 :(得分:0)

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

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

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

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

请回复输出。

答案 1 :(得分:0)

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

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

过去3天我也有同样的问题。虽然viewController已添加,但只有RootViewController即将出现,但不会YouTubeEmbedPlayer

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

答案 2 :(得分:0)

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