简体   繁体   中英

PushViewController doesn't do anything

This is the first time I'm trying to implement navigation from a tableView cell to another tableView using UINavigationController and it doesn't work for me. I'm NOT using nib file and I have a simple tableView that I present it in a modal dialog in my app, it works fine, now I added the disclosureInidcator to one of it's cell, to make the user enable to choose from a fixed number of options available from another list(tableView). For this purpose I have another class that makes the second tableView. the problem is now navigation from the cell(contains disclosure icon)in first tableview to second tableView doesn't do anything, no error, no nothing. I guess the way I setup the navigation controller would be wrong, the code doesn't fall in delegate, or datasource of the second class at all.

in First TableView in method : didSelectRowAtIndexPath I tried to catch that row, then call the second tableView like this:

 mySecondViewController *secondVC = [[[mySecondViewController alloc] initWithStyle:UITableViewStyleGrouped ]    autorelease];
  UINavigationController *navCont = [[UINavigationController alloc] initWithRootViewController: self];//not sure the first controller should act as the root controller?
 [navCont  pushViewController:secondVC animated:YES]; //it does nothing, no error,...

the second tableViewcontroller class contains all delegate and datasource methods, and initialization method:

 - (id)initWithStyle:(UITableViewStyle)style 
 {
     if ((self = [super initWithStyle:style])) {

    }
    return self;
 }

  and declared in interface as:
 @interface stockOptionViewController : UITableViewController {

}

I tried to play with viewDidLoad, but didn't help.

Please help me cause I have no clue and all sample codes found is based on using nib files.

Thank, Kam

Your navigation controller should be the root view controller of the app delegate's window, and the first view controller should be the root view controller of the navigation controller, then you can push new controllers onto it.

Please see the documentation for UINavigationControlle r.

At the moment, you are creating a navigation controller but not putting it anywhere, so asking it to push new view controllers is a little pointless. You have the right code, just not in the right order.

UINavigationController should be the root view controller. In the current code, navCont is not on the view stack, so it won't work. Instead of pushing myFirstViewController in your appDelegate, push the UINavigationController to the stack and add myFirstViewController as its root view controller.

You can present view control modally without nav controller

mySecondViewController *secondVC = [[[mySecondViewController alloc] initWithStyle:UITableViewStyleGrouped ]    autorelease];
[self presentModalViewController:secondVC animated:YES];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM