Programmatically add a UINavigationController to a UIViewController

I currently have a view configured as follows:

@interface BlogViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> { UITableView *mainTableView; } @property (nonatomic, retain) UITableView *mainTableView; 

As you can see, it has a UITableView in which I load all my data. However, when I call the following function:

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { SingleBlogViewController *viewController = [[SingleBlogViewController alloc] init]; [self.navigationController pushViewController:viewController animated:YES]; //[self presentModalViewController:viewController animated:YES]; [viewController release]; } 

Nothing happens. For some reason, my UITableView inside my UIViewController not pushing the view. Is it because it is not a UITableViewController ? I tried changing it to this, and it still doesn't work.

Did I miss something?

+6
source share
2 answers

I found the first parts of this blog post , useful for demonstrating how to create and use the UINavigationController programmatically without Interface Builder.

Some of the things I wish documents and study guides could emphasize to me are:

  • When you create a UINavigationController , you get the UIView and UINavigationBar for free (i.e. you do not need to add them separately and determine how to connect them).

  • You add the myUINavigationController.view property as the "main" view, and then click / pop UIViewController on the UINavigationController and they will automatically appear as visible in myUINavigationController.view UIView.

  • When you click on a UIViewController on a UINavigationController , the UIViewController.navigationController populates. If you did not click the view on the navigation controller, I assume the property is empty.

  • The time / place for programmatically adding buttons to the UINavigationBar does not occur when and where you create the UINavigationController , but rather for a separate UIViewController when they load when you click on the UINavigationController .

  • I needed to add the Finish button to the UINavigationController UINavigationBar in the viewDidLoad method of the first UIViewController clicked on the UINavigationController . Any UIViewController that I clicked on top of this first view automatically had a back button to go to the closed UIViewController .

  • If you set the title property of your UIViewController before you put it on the UINavigationController stack. The UINavigationBar header will be the title of your view. Also, any back buttons will automatically name the view you are returning to, rather than generally saying back.

+26
source

Please visit " How to Add a UINavigationController Programmatically "

Please follow the link and get all the information about the UINavigationController.

UINavigationController is a subclass of UIViewController, but unlike UIViewController, it is usually not intended to be a subclass. This is due to the fact that the navigation controller itself is rarely configured outside the visual effects of the navigation panel. A UINavigationController instance can be created either in code or in an XIB file with relative ease.

-3
source

All Articles