UINavigationController isn't pushing/displaying view - ios

New to iOS and objective C. Trouble with custom UINavigationController while developing an iPad app in XCode simulator. Appreciate your help greatly !
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
(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
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, assigns rootViewController to otherViewController within appDelegate.didFinishLaunchingWithOptions method. self.window.rootViewController = otherViewController.
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
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

Related

How to go back to UiTabBar home page from UiTableViewController that is loaded upon button click from a button within the homepage tab?

i have created a universal tabbed iOS application in Swift 2.0, the application has 3 tabs in the first tab, in the viewcontroller in storyboard i have placed a button upon which when pressed a UiTableView is loaded and it has a feature to add cell (a note taking feature embedded within the app), my issue is that once the UITableViewController is loaded i cannot go back to the previous page, its like this:
I have a TabBarController linked to a NavigationController which is linked to a HomepageViewController and When button is clicked, NavigationController linked to UITableView which shows ItemDetailViewController
My problem is that once i get to the UITableViewController i cannot go back to the home tab - HomeViewController
I have tried adding a UiBarButton to the top left of the UITableController and using poptorootviewcontroller , but it didnt work, any help will be appreciated.
According to my understanding, your tabbar controller is at the root of window. You can access it as self.window.rootviewcontroller. After that, you can use tabar.selectedIndex to switch tabs.

Unable Correctly to Add Navigation Buttons Using UIPageViewController for iOS

For my project UIPageViewController could be a good choice, so, I started with the template provided by XCode 6.4 starting new project. I used the template: Page-Based Application which has already the basic implementation of UIPageViewController. The opportunity to scroll the pages is working fine, however, I would like to add the navigation bar as well. After reading the articles on that topic I tried to embed DataViewController into NavigationController (Editor>Embed), and then added the Navigation Bar Button using the storyboard from Interface Builder. However, I cannot see that button when I compile the app. Moreover, it looks that the back navigation works for the pages when you press on the spot where Navigation Bar Button should be located, but button is not visible. Later I found out that the back navigation works not only on that spot but on all left margin of the view. It seems like a bug.
1. How to make Navigation Bar Back Button visible?
2. How to remove that buggy behavior when navigation reacts to the press of all the margin instead of just location of the button?
If you want to have the navigation controller show up, you need to change:
let startingViewController: DataViewController = self.modelController.viewControllerAtIndex(0, storyboard: self.storyboard!)!
so that startingViewController is the navigation controller your dataViewController is embedded in. You can do this by changing the storyboard ID of the navigation controller and saying something like:
let startingViewController: UIViewController = (self.storyboard?.instantiateViewControllerWithIdentifier("NavController"))!
However this is going to break the template as the rest of the code thinks the starting view controller is a DataViewController, so you will need to change that.
The "buggy behavior" is the standard page controller navigation mechanism when the transitionStyle is set to UIPageViewControllerTransitionStylePageCurl.

Unable to configure UINavigationBar for view embedded in Tab Bar Controller

I a writing an app (iOS8) that ultimately needs to load a UITabBarController via a segue from a UITableView. For the most part this setup can be done via Storyboards and works as expected, however I would also like to add a UIButtonBarItem to the destination view which is where the problems start.
A setup that works (without a UITabBarController) can be configured as follows
The button uses a "Show" segue to display the final view controller
The second UIBarButtonItems are added by copying over the Navigation Item from the first view controller (How to add buttons to navigation controller visible after segueing?)
If I run this in the Simulator, everything works as expected and I see both the back button and the desired "Add" UIBarButtonItem:
If I then embed the final view controller in a UITabBarController, the UIBarButtonItem I added disappears and so far any changes I have made to the storyboard setup (adding a UINavigationController in between the UITabBarContoller and the last view for example) or attempts to add the UIBarButtonItem programatically don't make a difference:
Is there anyway to get the final setup working with both a UITabBarController and UIBarButtonItems?
I have the same setup in one of my apps and it works fine. Not sure why you are having issues, but I did add a few lines of code in my custom Tab Controller that may help you. I think the issue is that the nav bar from the original navigation controller is still being shown, so subclass UITabBarController and put these lines in viewWillAppear:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationItem setHidesBackButton:YES];
[self.navigationController setNavigationBarHidden:YES];
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
In my app, the views before the tab bar controller were login/register views, so there was no reason to navigate back to them after entering the tab controller "stack," but I'm sure it won't be difficult to add a back button that accomplishes this. I believe you only need the [self.navigationController setNavigationBarHidden:YES]; line, which only hides the nav bar instead of hiding the back button or disallowing the pop gesture.
I know this is late but I just want to add swift 3 code.
The reason being that the NavigationBarA of the tabBarController is hiding your NavigationBarB that sits in between your tabBarController and the final ViewController. So you just have to set to hide the NavigationBarA
in viewWillAppear of your final ViewController you can add the following (without a need to subclass tabBarController)
self.tabBarController?.navigationController?.setNavigationBarHidden(true, animated: false)

iOS how to go from xib file to a view controller in tab bar

i have a tab bar application
i am using storyboards and also navigation bar in my app
in my app
FirstViewController (in tab bar) with a button go to the SingleViewController (xib file and not on tab bar)
in SingleViewController there is a button too. and i want to go to one of the controllers which is on tab bar
in singleviewController's button method i have this code:
AylikGirisViewController *controller = [[AylikGirisViewController alloc] init];
[self.navigationController pushViewController:controller animated:YES];
it goes to the controller but i see a black screen and empty screen also moving to the AylikGirisViewController gets hard (i mean very slowly)
so i think my way is wrong
any ideas for the right way?
if you are using storyboard, you can simply drag another view controller onto the storyboard and give name as SingleViewController, you can easily push the SingleViewController onto the FirstViewController if you embed the FirstViewController in UINavigationController. Use storyboard segue to push the controller. Then you can call UITabBarController Delegate method to show the different viewController.

Using my NavigationController with my ECSlidingViewController

What I'm trying to do
If started creating my App. I've got a NavigationController as my rootViewController. When the app is started it will open my LoginViewController. In there I do the Login-Procedure, if everything is fine. I'll start my ECSlidingViewController. Which has a Menu (UITableView) and a MainView (UITableView).
Until here everything is working fine. I can swipe and it show's my menu. Now the problem is starting. When I press a menu-item it perfectly starts my new ViewController and show's the content. But there it still show's the same NavigationBar - like in the ECSlidingViewController. So I got no possibility to tell the user what he is looking at, also I need to show him sometimes new options in the NavigationBar.
Question
How can I fix this problem? I'd always like to show the NavigationBar of the specific ViewController I'm actually using. If you guy's have some Codesnippets or a good Idea how to handle this problem. Please leave a comment bellow.
If you need codesnippets or something else, tell me I'll upload it! Thank you in advance!
Code
This is how I start my ECSlidingMenu:
[self performSegueWithIdentifier:#"loginPush" sender:self.view];
This is how I'll start a new ViewController:
UIViewController *newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:identifier];
Pictures*
You want to change your structure so that the ECSlidingViewViewController is the root view controller. This can either be from the start of the app or you can switch the root after login. The top view controller of the sliding controller should then be a navigation controller and you should set the root and push other view controllers into that navigation controller.
What you currently have breaks the link between the view controllers and the navigation controller because only the sliding view controller is pushed into the stack and its title (nothing about its navigationItem ever changes).
Probably the easiest solution would be to change the initial view controller in the storyboard (to the sliding view controller). In this case the login view would be presented as the root view of the navigation controller (which would be the top view). Then, after login you push the next view controller and then (after the animation completes) remove the login view controller from the nav stack.

Resources