How to dismiss a PopOver after another BarButtonItem has been pressed - ios

I have a ViewController that contains a navigation bar. In this navigation bar, there are 2 UIBarButtonItem: A and B.
When A is pressed, another ViewController is displayed as a PopOver (segue present as popover).
If I press anywhere on the screen, the popover is dismissed.
The problem is that if I press on B (the other UIBarButtonItem) the PopOver is not dismissed...
What should I do to automatically dismiss opened popovers when bar buttons from the navigation bar are pressed?

Related

Change back button label in navigation bar using Storyboard?

I have a navigation controller, with 3 view controllers.
Nav Ctrller -> VC1 -> VC2 -> VC3
Say I want the 'Back' button on VC2 and VC3 to read 'Previous' instead. In VC1, I selected/highlighted the nav bar item from Storyboard and changed the Back Button property to 'Previous'.
Now VC2 back button says 'Previous', but the back button on VC3 still says 'Back'. I thought I need to make the same change for nav bar item in VC2, but there is no nav bar item to select. I guess nav bar item shows up only in root VC?
Currently I am changing the back button label on VC3 by code. Is there no option to change the back button label on VC3 using Storyboard?
Thanks.
Drag a navigation item to your VC3

how to add slide menu close button on navigationbar

I have implemented the slide menu it has a close button but the close button goes under the navigation bar. How it brings it above the navigation bar and slide as menu slider.
Here is how I want the close button.
Try this :
let window = UIApplication.sharedApplication().keyWindow!
window.addSubview(menuView)
window?.bringSubview(toFront: menuView)

Swift: present view controller in same context as other view controllers?

Ok, I have an issue that I cant understand trying to present a view controller (the same instance every time, just like other tab item VCs) from an overall tab bar controller VC. My tab bar controller VC has 3 view controllers that it is connected to via storyboard, so 3 tab bar items appear on the tab bar. When the selectedIndex is changed, these view controllers just appear right there below the subviews of the Tab Bar Controller VC.
These subviews that should always be on top are the nav bar at the top and tab bar at bottom:
And this is great for those 3 view controllers. Problem is I need to access 1 instance of ANOTHER view controller that is NOT shown in the tab bar buttons via a button in the nav bar here.
My problem is no matter how I present it, this VC always pops OVER the tab bar controller VC, covering the tab bar and nav bar.
here I make sure only 1 instance is made:
if podcastVC == nil {
//print("IT IS NIL")
let storyboard = UIStoryboard(name: "Main", bundle: nil)
podcastVC = storyboard.instantiateViewController(withIdentifier: "podcast") as! PodcastViewController
//*NOTE: have to set other vars too, this is temp
podcastVC.urlStr = currentTrackUrl!
podcastVC.originalUrl = currentTrackUrl!
AudioPlayerManager.shared.play(urlString: podcastVC.urlStr)
}
self.show(podcastVC, sender: self)
podcastVC.modalPresentationStyle = .currentContext
podcastVC.definesPresentationContext = false
[1]: https://i.stack.imgur.com/1d6MZ.png
as shown by Swift: How to return to the same instance of my UIViewController
How can I make that VC present in the same context as the tab bar items? I have tried setting the layer of the nav bar to a z position much higher (like 10) but nothing works. What is wrong?
Modal view :
Can works for all view controllers
Is over all other view and need to be pop programatically (adding a button back manually for example)
Push View :
Only works in navigation controllers
Add automatically a back button in the navigationController
you should push VC and it will keep tabbar and nav
you can change modal present style

How to animate UIBarbutton item programmatically

I need to animate left bar button moving to right side of menu list view in slide bar menu view controller
How can i animate this in swift3.
UIView.animate(withDuration: 0.3, animations: { (Void)
}, completion:nil)
Simple Answer:
You can use a Cloaking in your code
1.create a BarButton on the window the appearance is the same as your left bar button on your viewController, and hide the left bar button on your viewController.
2.animate the BarButton which on the window to your ' right side of menu list view in slide bar menu view controller'.
3.on your slide bar menu view controller create a BarButton the same as your barButton, and remove the BarButton which on the window.
so it will realize your idea.

alternating between toolbar / tab bar

my app is structured as follow: UITabBarController > UINavigationController > ViewControllerOne > ViewControllerTwo.
the UINavigationBar has at the bottom the tab bar, now when the user navigates into the second view controller, i want to be able to hide the tab bar and replace is with a tool bar. i tried this code:
[self.navigationController.tabBarController.tabBar setHidden:YES];
[self.navigationController.toolbar setHidden:NO];
when i run the app the tab bar is hidden but the toolbar doesn't appear. plus, since the last VC is a table view controller, when i scroll through the cells there is a white gap between the table and the bottom of the view. how can i fix that?
That won't work because when you hide the tab bar like that the subviews won't be adjusted properly (that's why you get the white space). You'll have to use
self.hidesBottomBarWhenPushed = YES;
In your init method or awakeFromNib... and then
[self.navigationController setToolbarHidden:NO animated:YES];
In the viewDidLoad for example.
That way the tab bar controller's view is going to layout correctly it's subviews when you hide the tab bar. Just remember to call self.hidesBottomBarWhenPushed = NO; in your first view controller otherwise the tab bar is still going to be hidden when the second view controller is popped from the navigation stack.
Try to assigning toolbar with appropriate frame and adding it to self.tabBarController.view

Resources