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

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.

Related

Why is the tab bar not appearing throughout the app?

I have implemented a tab bar, but as I go through the app I am not seeing the tab bar. It disappears after I go to a certain page. This is how I implemented it. I have a tab bar connected to a vc which is embedded inside a navigation controller. So the hierarchy looks like this.
----UITabBarController
-------UINavigationController
-----------ViewController 1 with button to view controller 2 (I can see the tab bar)
----------------View Controller 2 (I can't see the tab bar)
It sounds like the segue that you get from view controller 1 to view controller 2 is a "present" segue, rather than a "push" segue. (If I recall correctly, Apple removed "push" segues from Storyboards recently.) Sadly, "present"ed view controllers appear in front of the navigation controller.
In order to do a "push" segue, you have to do it in code, e.g.:
- (IBAction)buttonTapped: (id)sender
{
ViewController2 *viewController = ...
[self.navigationController pushViewController:viewController];
}
i think you missed to initial tab bar as initial view controller

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 Storyboards - Re-use UIViewController

I've got the following structure setup in my Storyboard.
I've got a TabViewController (circled in red) that shows a UIViewController via one of its tabs by doing a push (circled in blue).
I want to re-use that UIViewController from the TabViewController. I'd like to 'push' it but I don't really have a navigation controller so I may end up displaying it as a modal.
However, I'm not sure how to handle navigation back to the TabViewController since in this case there's no navigation bar. Any suggestions on the best way to handle this?
EDIT
Is there a way to insert a Navigation controller when its displayed directly from the TabViewController?
Why don't you put your view hierarchy like this:
UITabBarController -> UINavigationController -> BlueViewController
This UINavigationController should be put in the viewControllers property of the UITabBarController instance. If you do this, you can push and pop as many view controller as you want and you can also hide the navigation bar if needed.
Cancel button whose action is [self dismissViewControllerAnimated:YES completion:nil];

PerformSeque from button

Currently I'm writing a iOS app with Xamarin.iOS and I wrote a custom UITabbarController named BaseTabbarController. In this ViewController I made a centered raised UIButton over the TabBar to achieve something like this:
So this means that in my BaseTabbarController there is a onClick delegate for my button. When the button is pressed I would like to performSeque(push) to a new ViewController. The following code gives me the error: "Could not find a navigation controller for segue 'searchSegue'. Push segues can only be used when the source conroller is managed by an instance of UINavigationController".
So what should I do right now? I'm not sure how to fix this..
My storyboard looks like this and I'm talking about the second row.
If the button which causes push segue is on tabbar then you an not perform push segue on it because tabbar controller is supposed to be a rootview controller and to have push segue your controller must have navigation controller as container.
For example MyViewController is controller for view A and OneMoreViewController is controller for view B now you want to call view B from view A then embed view A inside navigation controller
// Programmatically
MyViewController *vc= [MyViewController alloc] init];
UINavigationController *nav = [UINavigationController alloc] initWithRootViewController: vc];
If you want to add that View A in tabbar then add nav object inside tabbar.
Now you can call viewB from view A using Push segue.
// and if your using storyboard then
Select the view which you want to embed inside navigationcontroller and choose Editor\Embed In\Navigation Controller from menu bar. that's it.
You've got a push segue hooked up from your tab bar controller to the navigation controller on the second row -- that's not right. That should be a relationship segue (i.e. one of the tab bar controller's view controllers, a second tab).
After Edit:
To be able to push that controller from any other controller on screen, all the base controllers in each tab will have to be a navigation controller. As long as that's true, you should be able to do this. The basic procedure would be to find out which navigation controller's stack is onscreen (with the tab bar controller's selectedViewController method), and perform a push in code from that navigation controller, using pushViewController:animated:. In the storyboard, you would want to have the controller you're pushing be disconnected from everything (no segues), and have an identifier, so you can get it from the storyboard to do the push.

Moving from a view controller to a tab bar controller when using storyboards ioS5

I created a tab bar controller in a story board which is working perfect. Now i need to move from a view controller to this tab bar controller. I do not have a separate class for the tab bar controller. However I tried creating a class for this tab bar controller but when i call it/initialise it, it just gives a new tab bar instead of whats on the storyboard. Ive been stuck with this for a while now so any help would be appreciated. So application works this way. viewcontroller1 -> viewcontroller2 -> tabbarcontroller (which has a table view and a map view)
If I understand your question correctly, what you want to do is assign an identifier to the TabBarController in the Storyboard, in the Attributes Inspector, and then use that to programmatically instantiate the controller using this code:
UITabBarController *tabBarController = [self.storyboard instantiateViewControllerWithIdentifier:#"TabBarIdentifer"];

Resources