Swift - Hiding Tab bar in PageViewContoller scenes - ios

I set up a series of onboarding scenes for my app using this tutorial, and elsewhere in my app use a TabViewController. When I run the app, the Onboarding scenes have a blank tab bar at the bottom.
I've tried ticking "Hide Bottom Bar on Push" from all 3 views on interface builder:
I've also tried adding
self.hidesBottomBarWhenPushed = true to the override func viewDidLoad() functions of the ViewController, PageViewController and PageContentViewController. No joy!
Also tried self.tabBarController?.tabBar.hidden = true in the same places.
Elsewhere I've found references to this:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showLogin"{
println("showLogin seque called")
let bottomBar = segue.destinationViewController as LoginViewController
bottomBar.hidesBottomBarWhenPushed = true
bottomBar.navigationItem.hidesBackButton = true
}
}
but, I don't have any named segues, so not sure how to identify the segue.
Any help would be amazing!
Thanks

To give the Segue name, first choose the segue and then go to Attributes Inspector.
Below there you find Storyboard Segue, from there you provide Identifier name in Identifier Box.
Thanks

Related

How to hide TabBar in RootView ChildViewControllers

I am troubling in hide UITabBarController inside the TabBar item ChildViewControllers
For Ex. Suppose We have two tab bar item in my home screen and first tab bar item is selected and i want to go with navigate first tab bar then i want to hide TabBar in first TabBar item childViewControllers
I found solution for this
[self.tabBarController.tabBar setHidden:YES];
use hide Tab bar item in viewDidLoad using hidden property.
And Select Under Opaque Bars option in storyBoard ViewController.
before view is pushed or showed. hidesBottomBarWhenPushed variable on viewcontroll will be checked and automaticlly hides bottom bar. you can use it in two ways:
1- override it in child controllers:
override var hidesBottomBarWhenPushed: Bool {
return true
}
2- you can set it before performing segue in prepare for segue:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "identifier" {
segue.destination.hidesBottomBarWhenPushed = true
}
}

Swift Hide Button In Another View Controller

Currently working on my first IOS application. I have a purchase button, on success this currently sets a test button on the same view controller to hidden. Code is as follows
Decleration
#IBOutlet weak var Test: UIButton!
hide button on successful purchase
Test.isHidden = true
Now this works on my Test button, which is sat in the PurchaseViewController,class is the MasterViewController.Swift. (Purchase button that initiates this method is also in the same view controller)
PlanViewController also has a button, and class is also linked to MasterViewController.Swift. This has a separate button that i wish to hide on success of the purchase button.
When I utilise the same code as above for the button, it crashes, is their a limitation on manipulating other view controllers while you are not in it? I would have thought this worked given that they both have the Masterviewcontroller.swift as the class
Thanks
Although sometimes possible, it's generally not a good idea to directly manipulate one view controller's view from another view controller, as you are trying to do. Here is how I would do what you are trying to do.
First, set a segue identifier between your two view controllers by clicking on the segue in the storyboard and going to the attributes inspector. I suggest goToMasterViewController
In both MasterViewController.swift and PurchaseViewController.swift declare a variable var buttonHidden = false
In PurchaseViewController.swift add the following code, which will be called just before your segue to MasterViewController is performed:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if(segue.identifier == "goToMasterViewController") {
let destinationController = segue.destination as! MasterViewController
destinationController.buttonHidden = buttonHidden
}
}
When you hide the button in PurchaseViewController, also set buttonHidden = true
And finally in MasterViewController.swift:
override func viewWillAppear(_ animated: Bool) {
testButton.isHidden = buttonHidden
}

Bar button action on ViewController in ViewContainer

I have a container embedded in a ViewController with a navigation bar. The ContainerView contains another ViewController with some textfields.
When the ContainerView is first displayed, the textfields are disabled.
What I would like to do is add an edit button to the navigation bar which enables the textfields.
Basically, is it possible for a bar button item in a viewcontroller to have an action on another view controller displayed in a container?
in this case you can do a little trick
the bar button will be in the ViewController but we can store the content of the ContainerView in a variable in the first ViewController
to do that i would suggest to make the content of the ContainerView has a custom class so you would write a function in it
here is an example on how to catch the content of the ContainerView
class ViewController: UIViewController{
weak var containter: ContainerViewController!
#IBAction func menuAction(_ sender: UIBarButtonItem) {
//do what you want containter.doAction()
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?){
if let vc = segue.destination as? ContainerViewController {
self.containter = vc
}
}
}
Always the case. I've been looking for an answer for hours, as soon as I ask I figure it out.
I'm not sure its the best way to do it but I just made an edit bool controller by the edit button. Then used:
var child = self.childViewControllers[0]
child.viewWillAppear(false)
This reloaded the data and if it was in edit mode enabled the textfields. Works fine!

Disabling segue animation

I want to Show (e.g. push) segues in my storyboard, to connect my viewcontrollers and my navigation controller. Then the navigation bars on the viewcontrollers will show correctly.
For example: With show detail or present modaly, the navigation bar will disappear
But I don't want segue animation.
Xcode is giving the warning like : "Disabling segue animation is not available prior to iOS 9.0"
And I wants deployment target of iOS 7.0 or 8.0
How can I solve this?
Thanks in advance.
You can disable animations before performing the segue and after enable it again.
UIView.setAnimationsEnabled(false)
self.performSegueWithIdentifier("next", sender: nil)
UIView.setAnimationsEnabled(true)
This will perform the segue without the animation.
Click on segue arrow in Main.Storyboard and then:
Check out Animates
If you want to switch animate state in the code, You can duplicate your segue in the storyboard, with different identifiers, and the same origin and destination. Then make one of theme animates and the other not. Then, do performSegue with the desired identifier.
class MyNavigationController : UINavigationController {
var firstTransitionAnimated : Bool = true // or false, based on initialization
override func viewDidLoad() {
super.viewDidLoad()
var properSegue = firstTransitionAnimated ? "animated_segue" : "not_animated_segue"
self.performSegue(withIdentifier: properSegue, sender: self)
}
}
I made a custom segue, using the Swift answer in this thread:
Push segue in xcode with no animation
So:
class ShowNoAnimationSegue: UIStoryboardSegue {
override func perform() {
let source = sourceViewController as UIViewController
if let navigation = source.navigationController {
navigation.pushViewController(destinationViewController as UIViewController, animated: false)
}
}
}
And in Xcode, in the Attributes Inspector of the custom Segues, I have checked the 'Animates' box (YES). Now the warning is gone, so that is why I am answering my own question.
I am not really sure yet if it is a durable solution.

Different behavior for segue using UISearchController

I must be doing something wrong here.
I have a UITableView, and have implemented a UISearchController.
I have a Prototype cell linked to the details screen and pass the selected value in the prepareForSegue method.
For the normal view controller, all works OK, a row is selected and the details screen pushed (i.e. slide in from right).
However when there is an active search, using the UISearchController, the details screen is presented modally (i.e. slide up from bottom of screen) without the UINavigationBar (so there is no possibility to go "back")
I am not using didSelectRowAtIndexPath since I have used storyboard to push the details screen
Why is the presenting animation different when the same code in "prepareForSegue" is being correctly called in each case:
// MARK: - Navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier! == "PresentContactDetail") {
// pass person details from selected row
if let selectedRow = self.tableView.indexPathForSelectedRow()?.row {
let selectedPerson = self.visibleResults[selectedRow]
(segue.destinationViewController as ContactDetail).personRecord = selectedPerson
}
}
}
Any suggestions gratefully received.
in ViewDidLoad of UITableViewController set
definesPresentationContext = true

Resources