开发者

UINavigationController isn't pushing/displaying view

New to iOS and objective C. Trouble with custom UINavigationController while developing an iPad app in XCode simulator. Appreciate your help greatly !

  1. Created project (view based application) in XCode. Application currently has two views. Home Page and a Detail View. Want a Home Page like Facebook or Linkedin iPhone App Home page...where you have bunch of icons/images on the home page, and click on each to get more details

  2. (With limited knowledge) concluded Home page can't be TableView, SplitView or TabBarView. Don't want any tabs or table view style in Home page (as explained above). So couldn't start XCode project with "Navigation Based Application" template

  3. Didn't add UI elements from IB to MainWindow.xib, rathar homepage UI elements are in the otherView.xib created by the project template. The project template, assign开发者_运维知识库s rootViewController to otherViewController within appDelegate.didFinishLaunchingWithOptions method. self.window.rootViewController = otherViewController.

  4. Added a NavigationController through IB to otherView.xib. Added outlet for navigationController. otherView.h has following UINavigationController *navigationController; @property (nonatomic, retain) IBOutlet UINavigationController *navigationController; referencingOutlet for navigationController is connected to File's Owner

  5. When App is launched Home Page (served by otherViewController) comes up. When clicking on an icon in Homepage (an ImageView with Button behind), Detail View doesn't show up, if I call

    [self.navigationController pushViewController:DetailViewController animated:YES]; (within the action method, that's handling touchUpInside for that button.)

but detail view shows up if I do either

self.view = DetailViewController.view; or

[self.view addSubview:DetailViewController.view];

So doesn't seem to be a problem with DetailView loading it's nibfile etc. No problem also in button click/touch event capture etc.

A. When I examine the navigationcontroller in the debugger, it has both the two viewControllers in its stack, with rootView/ Home page at index 0, and Detail View at index 1. navigationController is not null. Any ideas on what am I missing ?

B. Do I need to add a navigationBar to both the home page (in whose view navigation controller is added) and the detail view ? I have added a navigationBar to the detail view. I don't need a navigation bar in the home page UI.

C. When the detail view shows up through the addSubview call or self.view assignment (as mentioned above), the navigationBar doesn't show the back button (which should say "Home"). Both view Controller is setting appropriate title , using self.Title = "Home" or "Detail".

Appreciate your help. Thanks


In the appDelegate, you need to make navigation controller a property and then write:

self.window.rootViewController = self.navigationController;

in application didFinishLaunchingWithOptions: method. Then push otherViewController onto its stack. I think the mistake you're making is adding UINavigationController to UIView instead of the other way around, which is the correct way!


what you should do too in your xib file, make sur that you view is in a navigationcontroller

the tree of your xib file should like this :

  • your appdelegate
  • window
  • navigation Controller
  • navigation bar
  • and your rootviewcontroller
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜