0

Trying to push new controller into navigationController, Not sure why it is not woking. 1) I checked the instance of secondViewController also does not work. 2). tried suffixing '.xib", also not working. 3) Tried bundle:nil also not working.

I am using ARC. Can someone point out what is the issue here ?

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@" YOU SELECTED ROW ..");
    secondViewController *secController = [[secondViewController alloc] initWithNibName:@"secondViewController.xib" bundle:[NSBundle mainBundle]];
    NSLog (@"View Controller %@ ", secController);
        [self.navigationController pushViewController:secController animated:YES];
    }
Whoami
  • 13,930
  • 19
  • 84
  • 140
  • Why are you using ARC but not Storyboards? That may solve your problem. Also can we get some more code like your UINavigationController instantiation and what you mean by its not working? Is it crashing, coming in blank, just not doing anything at all? What does the NSLog for secController show? – Ryan Poolos May 05 '12 at 03:29
  • Have you implement UINavigationController in your MainWindow.xib file? – Ravi Kumar Karunanithi May 05 '12 at 06:12

3 Answers3

0

You don't need to pass the bundle in if the nib is located in the main bundle. Passing in nil will work, so change this:

[[secondViewController alloc] initWithNibName:@"secondViewController.xib" bundle:[NSBundle mainBundle]];

To this:

[[secondViewController alloc] initWithNibName:@"secondViewController" bundle:nil];

You can also take advantage of the fact that UIKit will look for a nib with the same name as the class and pass nil in for the nib name.

Brandon A
  • 926
  • 7
  • 6
0

I edit your code just try this.

 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@" YOU SELECTED ROW ..");
    secondViewController *secController = [[secondViewController alloc] initWithNibName:@"secondViewController" bundle:nil];
    NSLog (@"View Controller %@ ", secController);
    [self.navigationController pushViewController:secController animated:YES];
}
vishiphone
  • 750
  • 7
  • 14
  • And also check your file owner of second view controller xib.In xib any warning connection should not be there. – vishiphone May 05 '12 at 05:21
0

Do you intailize navigation controller? Check self.NaviagationController is it in memory ? May be 0*0

Mangesh
  • 2,257
  • 4
  • 24
  • 51