开发者

Why does the view nib doesn't open after cell is selected?

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)tab开发者_Go百科leView:(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;

}


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;


Try this:


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

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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜