0

I created the nib file and I did all the connections correctly. When I run the application and select a cell, the new nib doesn't open at all. Please help!

    - (void)tableView:(UITableView *)tableView 
 didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    //Get the selected country
NSString *selectedCountry = [[NSString alloc] initWithFormat:@"you pressed for this."];

//Initialize the detail view controller and display it.
DetailViewController *dvController = [[DetailViewController alloc] 
                                      initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];

dvController.selectedCountry = selectedCountry;
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
dvController = nil;

}
Jovany
  • 1
  • 1
  • Release `selectedCountry` or you leak. Is it on a navigation controller? Try `NSLog(@"%@ %@", self.navigationController, dvController);` immediately after `pushViewController:animated:` method and let us know the result. – Deepak Danduprolu Jun 25 '11 at 07:11
  • which mistake do you get? also `dvController = nil;` do not need because you delete dvController from memory before. – sherilyn Jun 25 '11 at 07:23
  • @Deepak, I released selectedCountry in DetailViewController.m and tried what you told me but no luck! – Jovany Jun 25 '11 at 07:31
  • @Sherilyn, I actually don't get any errors. It builds perfectly fine but the nib doesn't load at all when I click on the cell. I also tried deleting the dvController = nil but it didn't do anything. Thanks though! – Jovany Jun 25 '11 at 07:34
  • @Jovany I wanted to know what it printed on the console. I didn't think it would fix the issue. :) – Deepak Danduprolu Jun 25 '11 at 07:36
  • @Deepak, nothing shows up on the console. It simply prints session started.... and thats about it. – Jovany Jun 25 '11 at 07:42
  • Your code is fine. Try to re-check connection in IB, name of NIB file. Also create a test view in `DetailViewController` and add it to self.view to see that your controller is really loaded. Do this in `viewWillAppear` or `viewDidLoad`. Create breakpoints in these methods, and look what happens. – sherilyn Jun 25 '11 at 08:16
  • Check this SO post. http://stackoverflow.com/questions/1068368/why-doesnt-initwithnibname-work-for-my-uiviewcontroller-subclass [It doesn't load the view...](http://www.iphonedevsdk.com/forum/iphone-sdk-development/76635-doesnt-load-view.html) – Jhaliya - Praveen Sharma Jun 25 '11 at 07:11

4 Answers4

3

It looks like (based on no output being logged for the NSLog statement) that you don't have your delegate set properly as it would've otherwise logged null or some object value. You need to recheck your IB connections or if you've done it programmatically then do tableView.delegate = self;

Deepak Danduprolu
  • 44,595
  • 12
  • 101
  • 105
0

Try this:


DetailViewController *dvController = [[DetailViewController alloc] 
                                      initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];

dvController.selectedCountry = selectedCountry;
[self.navigationController pushViewController:dvController animated:YES];
dvController = nil;
0

Don't both release the dvController AND set it to nil - do only one.

Dustin
  • 6,783
  • 4
  • 36
  • 53
Tushar Chutani
  • 1,522
  • 5
  • 27
  • 57
0

Hope you are trying to load the detailvewcontroller from a listviewcontroller. And the table view is a member of listviewcontroller.

Posssible reason for the issue.

If you are adding listviewcontroller.view as a subview to any other viewcontollers view then

[self.navigationController pushViewController:dvController animated:YES]; don't work.

So you should get an instance of your app delegate and do the following.

YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];

[appDelegate .navigationController pushViewController:dvController animated:YES];

Check around this. If this is not a reason for your issue then please let me know the console output Deepak asked you.

Adarsh V C
  • 2,314
  • 1
  • 20
  • 37