开发者

How to add a UINavigationController to my UITableViewControllerSubclass?

My app is a tab bar application, which one of the tabs is a TableViewController instead of a viewController which works fine (the table displa开发者_运维问答ys great) but where and how do I add UINavigationController to it? :-)


You can do this 2 different ways... in IB or code. If I'm dealing with a TabBar I usually do it in IB. All you have to do there is is drag a NavigationController object where your tableview object currently sits... then just make your tableviewcontroller the first child of your new navigation object.

TabBarController
-(Tab Bar)
-NavigationController
--(Navigation Item)
--TableViewController

or

If you want to do it in code... I would just set it up within your app delegate (usually because a tab bar is at the highest point in your app... meaning it appears right away after loading):

// Create a tabbar controller and an array to contain the view controllers
tabBarController = [[UITabBarController alloc] init];
NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:numberOfTabs];

// setup the view controllers
UINavigationController *myNavigationController;
myNavigationController = [[UINavigationController alloc] initWithRootViewController:myTableViewController];

// add to tab bar controller
[localViewControllersArray addObject:myNavigationController];
tabBarController.viewControllers = localViewControllersArray;

// add the tab bar to the window
[window addSubview:tabBarController.view];

You should then release the objects you just created since they will be retained by the TabBarController and Navigation Controller. Hope this helps


As Ryan noticed you can make it easily using IB. Here is how you can achieve this:

  1. Launch Xcode and create new Tab Bar Application project.
  2. Under resources group find MainWindow.xib and double click it to open in Interface Builder.
  3. Next, select Tab Bar Controller object and open Inspector window (Command + Shift + I).
  4. Notice "View Controllers" section in Inspector (

    How to add a UINavigationController to my UITableViewControllerSubclass?

    ) then click on View Controller popup and change value from View Controller to Navigation Controller.

That's it! Now you can use your UITableViewController subclass inside this UINavigationController.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜