iOS/iPhone didSelectRowAtIndexPath self.navigationController pushViewController not working
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", "Bu开发者_开发百科ildingDescriptionViewController: 0x7e73d30" )
2011-06-27 18:03:15.844 something[16331:207] ViewControllers after pushing: ( "BuildingProfileViewController: 0x7e89680" "BuildingDescriptionViewController: 0x7e73d30" "BuildingDescriptionViewController: 0xcc2c8e0" )
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.
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.
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: ( "", "", "", "", "" )
精彩评论