Button not click behind Navigationbar in swift 3 - swift

I use a button over a view behind the navigation bar by code and unselect the property UnderTopBars in storyboard due to which I have set the y coordinate = -45.when my navigation bar slide above than the button show up but its not clickable .Not fire the touchup inside method
my code is
searchBtn.addTarget(self, action: #selector(ViewController.searchAction(_:)), for: .touchUpInside)
func searchAction(_: UIButton) {
print("Button Tapped")
}
my button look like after hide the navigation Bar

you can use debug view hierarchy for if any view is on top of your button on not???
and also make sure your button is enabled.

Related

How to pass Data from one view controller to another view controller without using seague and storyboard

Please Do it Without Using Storyboard.
when I click on radio button in the popup.When I click on 'Ok' The title of the radio button will be the button title in main view controller.
You can get title from UIButton.isSelected property. You can set title in viewDidLoad method like
YourButton.setTitle("Title", for : .normal)
YourButton.setTitle("Selected Title", for : .selected)

Swift Trigger click in textfield

In my app I'm using some pickerviews that appear when I click on a textfield, that works fine!
I wanted to do the same when I click on a Left Bar Button Item. I can't do it with the button because buttons doesn't have inputView property, needed for associate the pickerview to the button (in this case). So I want to have a hidden textfield that is programmatically clicked when I click on the button (when it's clicked it show the pickerview and change the button name, that's all done)
Is that possible?
The best I can do right know is something like this
txtFantasma.perform(
#selector(becomeFirstResponder),
with: nil,
afterDelay: 0.1
)
It works fine, but just work at the first time.
EDIT1:
I've tried to make it with buttons... The popover is showing, now I wanted to click in one button and dismiss the popover and pass data to the main viewcontroller.
class ViewPopup:UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
}
#IBAction func btTituloAsc(_ sender: UIButton) {
let next = self.storyboard?.instantiateViewController(withIdentifier: "mainview") as! ViewController
next.ordenacao = "TituloAsc"
self.present(next, animated: true,completion:nil)
}
}
This works, but the main controller is showed without the Navigation Bar! How can I do the same but show de Navigation Bar?
The simplistic way to do it, is just display the pickerView as a popover once the user taps the button and then change the buttons title accordingly.

Xcode TabBar controller logout issue

I have a tab bar controller in my app. one of the tabs has a navigation Controller with a bar button. clicking the bar button segues to a tableViewController which has another button in it. The button segues to yet another TableViewController which includes a logout button.
#IBAction func logoutDidTap(_ sender: Any) {
try! FIRAuth.auth()?.signOut()
when I login to the app again and click on that tab, it takes me to the TableViewController with the logout button instead of the beginning of the tab. How can I fix this?
Since you have placed all the view controllers under the navigation controller, so you can easily pop them from the navigation stack when you are done logging out. Here's how to do it:-
#IBAction fund logoutDidTap(sender:Any){
try! FirAuth.auth()?.signout()
var viewControllers = navigationController?.viewControllers
viewControllers?.removeLast(2) // views to pop
navigationController?.setViewControllers(viewControllers!, animated: true)
}

Avoid showing "back" for back button when navigation title is long in Swift

There is a navigation in my project which I want to config it's navigation back item.
First case: When the UINavigation title is long the title of back button is set to "back"
replacing back button title to "back"
Second case: when it is longer this "back" is not shown.
delete back button title and just show back icon
But I want to show just back icon in the first case too.
Swift 3 - Through Storyboard:
To make navigation bar back button have only back arrow and no "Back" text written, follow the steps:
Go to navigation bar of the root view controller(titled "Home" in screenshot below)
Go to its attribute inspector. Set the back button to a space as shown below:
And that's it!!
This is the simulator screenshot:
Hope it helps!
Add this in viewDidLoad of ViewController which is pushing next ViewController (View Controller Linguini Arabbiatta)
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
It will show just a back icon in all the View Controllers which are pushed from that View Controller.
Try this code
if let title = self.navigationController?.navigationBar.backItem?.title {
if title.characters.count > 5 {
self.navigationController?.navigationBar.backItem?.title = "Anything Else"
}
}
Here's Objective-C
[self.navigationItem setHidesBackButton:YES];
Here's Swift
self.navigationItem.setHidesBackButton(true, animated:true);
Edit: if you wish to remove the text only, then here's Objective-C
[self.navigationItem.title = #""];
Here's Swift
self.navigationItem.title = ""
Then you'll need to refresh the nav bar
self.navigationController?.navigationBar.setNeedsLayout()
self.navigationController?.navigationBar.setNeedsDisplay()

how hide tap bar on another controller before show everything else

I have a simple tap bar example. And for my next view i have a ViewController with tableView and on bottom textInput. when i want hide tap bar i have a code:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject? {
if segue.identifier == "showMe" {
(segue.destinationViewController as! MyViewController)
destinationController.hidesBottomBarWhenPushed = true
}
}
and on my next view when i tap a row on tableView i see first rendering tap bar and then tap bar is hidden and on last input Edit goes down :( how hide this tap bar before show next screen ?
This isn't exactly the best solution, but its a workaround:
set destinationController.hidesBottomBarWhenPushed = false
set contraints properly in your view controller (as if there is no tab bar)
use the following code (as shown) in the view controller where you want to hide the tab bar:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.tabBarController?.tabBar.frame = CGRectZero
self.tabBarController?.tabBar.userInteractionEnabled = false
}
This will make sure that the tab bar is hidden. Now the Autolayout constraints will make sure your view displays correctly with the tab bar height as zero.