开发者

Problems with pushViewController

i have an application where a there is a root view controller which pushes another a view controller into view. this view controller shows a table. when a cell is selected, it pushes to another view controller. The first push works, but the second doesn't. Here is my code for the selection of the cell in the table:

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

TwoViewController *two = [[TwoViewController alloc] initWithNibName:@"TwoViewController": bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:two animated:YES];
[two release];

Any i开发者_如何转开发dea what i've done wrong? the codes I've used for both pushes are nearly identical... I've tried this with putting this code in the touchUpInside event for a UIButton as well, but it does not work. My guess is that there is no navigationController to push the view, but I don't know. Please help!


Did you change the -initWithNibName:bundle method on TwoViewController? My guess is it doesn't initialize correctly (i.e.: the method doesn't initialize the super class correctly).

Edit: I think I found the error, it's kind of obvious, actually.

Please check this code you posted:

initWithNibName:@"TwoViewController": bundle:[NSBundle mainBundle]];

The error is near the @"TwoViewController": string, an extra semicolon that should not be there, change it to:

initWithNibName:@"TwoViewController" bundle:[NSBundle mainBundle]];


Log both 'two' and self.navigationController,

NSLog(@"two = %@", two);

NSLog(@"self.navigationController = %@", self.navigationController);

First you'll get to know, if one of them is nil (or both) and whether tableView:didSelectRowAtIndexPath: gets called at all.


Its navigation controller problem.Check it properly


If the new view controller is part of a view, it probably doesn't have a navigation controller. Check if navigation controller is nil before pushing.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜