Adding button which should be visible in all view controllers - objective-c

How can I make a button or any view which should be visible in all the view controllers and its action can be called from all the view controllers? Popping and pushing of viewcontrollers should take place behind that button. I don't have any code but I have a reference app, Moise Bently, in this app it has a button on top right corner.

Try adding _yourView/button to your window... you can do this in didFinishLaunchingWithOptions also you can do [self.window bringSubviewToFront:_yourView] when required.. if you add some other view over it.

Related

Create back button

How do I create a custom back button on one of my storyboards, when I do a segue and I say push it creates a back button on Mac with but when I do a modal or model it does not create a back button?
Modally presented view controllers do not automatically get close buttons.
self.navigationController.leftBarButtonItem = ...
A pushed view controller will automatically create a back button if the navigation controller is shown.
You will have to create your own back button. In the view controller that you have presented via the modal transition, you have to put a toolbar on it. Put it at the top and if using autolayout set the constraints top, both sides and height. Then place a barbuttonitem in the toolbar. You can select a system button like done or cancel. Make sure the new view controller is the class that you created. Now you can control drag from the barbuttonitem to your .h file and connect an IBAction. Call it dismiss or something like that. In that method call [self dismiss viewcontroller:animated completion:nil]. This will bring you back to the original view controller. I am not a my computer right now so I am not sure the exact wording of the dismiss method, but it will auto fill for you. Good luck.
As Douglas explained, you need to create property of the button (UIButton or BarButtonItem) and in the viewcontroller .m file connect
- (IBAction)backButton:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
with the button. This will dismiss the current view controller and bring you back to the previous one :)

Bar Button Item : IBAction not fired in View COntroller

At the bottom of the Detail View Controller of a Split View Controller, I have added a Toolbar in the Storyboard. I have added three Bar Button Items in this Toolbar. Each Bar Button Item is hooked to its IBOutlet in the private interface of the Details View Controller, and also hooked to its IBAction implementation in the same controller, for example:- (IBAction)shouldPresentView:(UIBarButtonItem *)sender
The main view contains:
A Webview.
A small rectancgle view at the bottom of the screen, below the webview, created and added programmatically, and containing various buttons. All the buttons stay operational.
When touching any of the Bar Button Items, the button is temporary highlighted, but none of the IBAction methods is triggered (a NSLog() statement in every method is never executed).
After searching and reading equivalent topics, I went through several solutions:
I added manually the Details View Controller as the delegate of the Toolbar in the View Did Load method of the Details View Controller.
I emptied the cache of the Derived Data of the Product.
I checked that every IBOutlet has an address and is not nil.
I tried to add an action SEL manually in the View Did Load method for every Bar Button Item.
I removed the rectangle bottom view to be sure that it was not interfering with the responder chain.
I added a Bar Button Item in the Navigation Bar to check if the same problem occurs: no, the Bar Button Item fires the IBAction method.
Any help would be appreciated.
Developing with iOS 7 SDK in Xcode 5.0.2
The issue was coming from a Tap Gesture that I added to the main view to collect touches on the web view. So the touch on the Bar Button Items was probably captured somewhere by the main view before reaching the UIButtonBarItem. I changed the target of the Tap Gesture to the web view – more logical – and the issue has been solved.

Tab Bar controller disappearing when moving to another view (iOS SDK, Using storyboards)

I am building an iPhone app using storyboards and I have a problem with the tab bar controller. On one of the views that is linked from the tab bar controller (view1), there is a button that leads to another view (view2). On View2, there is a button that leads back to View1. Very straight forward. But when I go from view1 to view2, the tab bar disappears, and even worse, when I go back to View1, the tab bar is still gone...
How can I fix that? (I have yet to put ANY code in the app, there is only the storyboard and the apple provided AppDelegate Class (and also a main file I suppose, but I am not intending on touching that).
Any Reply is Highly appreciated!
If you do a modal segue from a view that is a tab bar view, it will get rid of the tab bar for the modal view you are presenting.
Secondly, when you segue you are creating a new instance of the view controller. So I am guessing you are segueing from view1 to view2 and losing the tab bar, then you are segueing back to view1. At this point you have created view1, view2, and a second copy of view1 that does not have a tab bar.
I would suggest one of two things.
1.) If you want to keep the tabs at the bottom when you segue from view1 to view2, then click on view1, at the top of the screen select Editor/Embed In/ Navigation Controller. This will embed your view1 in a navigation controller. Then if you change your segue from Modal to Push it will keep your tab bars at the bottom. The navigation bar at the top also make it easy to go back from view 2 to view 1 the correct way (by popping the view) rather than creating a new segue. If you do not like the navigation bar, then you can change the "Top Bar" property to "None" in the inspector. You will then need to create some other way in view2 to get back to view1. (BY POPPING THE CONTROLLER, NOT BY SEGUEING)
2) If you don't want to set up a navigation controller you will have a little bit harder time keeping the tab bar stuff at the bottom of the view2 controller. In fact, I'm not sure you can do it at all with a modal segue, you'd probably have to write some type of custom segue. Either way, If you want to transition back to view1 and get to the correct controller (not a new version without the tabs) then you need to attach an action to whatever button you are using to segue and use the following code (I also attached the code for navigation controller push segues, in case you create a navigation controller and get rid of the navigation bar.)
For Modal Segue:
[self dismissModalViewControllerAnimated:YES];
For Push segue:
[self.navigationController popViewControllerAnimated:YES];
Your best bet is to use the navigation controller method, as you are assured to keep your tabs. You can then either use the navigation bar to return (the easy way, no code needed) or you can get rid of it and use a button and the code above.
Good luck!
I had the same problem, i know this is an old question but [self dismissModalViewControllerAnimated:YES]; is deprecated in iOS 6.
What i used is:
[self dismissViewControllerAnimated:YES completion:nil];

UINavgationController and UITabBarController together

I am trying to create a view with a TableView in the center, NavigationBar on top, and a TabBar with 5 items. The TabBarItems will be attached to 5 different modal views. And the tableview can select an item and "navigate" to another tableview or detail view.
Following the Apple doc, I tried to create a NavigationController in a TabBarController in IB, but failed. I read all the posting regarding to this topic, and they all described a NavigationController inside one of the TabBarItem. But that is not what I want. The TabBarController and NavigationController are separate controller doing separate thing in the same view.
So I start wondering maybe it is a design issue. I should just use a NavigationController and add the TabBar as objects and not controller in the view.
Am I going the right track or is there a better way to combine NavigationController and TabBarController in IB to do the job that I want. Am I making sense?
If the tab bar is actually being used as a tab bar, it sounds like you want 5 navigation controllers, one for each tab.
If the tab bar is being used as a toolbar to hold buttons that bring up modal view controllers, push views onto the navigation controller, or other actions besides what a tab bar is intended for, use a UIToolbar instead. UINavigationController actually has toolbar support built in, just set its toolbarHidden property to NO and set the toolbarItems property on each view controller that can go inside the navigation controller to an array of appropriate UIBarButtonItems.

Showing UITabBar in a separate view

I'm new to Xcode/Cocoa/Objective-C, and I need a little help.
Essentially, I'm working on an app in which the first window has a couple of buttons; this is the Main Menu. When pressed, a button opens up a separate view that has a UITabBar and a Navigation Bar at the top that leads back to the Main Menu.
My two questions:
How do you make a UITabBar appear only in certain views?
How do you create a button to switch between nib files and not only views?
I've been using a RootViewController and TabBarController classes to be used by my RootView.xib (which is the main menu that holds the buttons) and a couple .xib files for the tab bar views (one nib file has each of the two views for the tab bars and nav bar).
I'd really appreciate any help with this!
present your view with buttons modaly in your appDelegate. When you dismiss this view set a view controller with setSelectedViewController: as rootController in your TabBarControllers array.
Hope this helps