I have one tableview that cut off in the last row of the cell. But when i click one cell, and click back from the next viewcontroller, my tableview is correctly shown all the cell.
Whast wrong with my tableview?
I set my tableview like this in home controller:
in ViewDidLoad:
self.automaticallyAdjustsScrollViewInsets = false
override func viewDidLayoutSubviews() {
self.myTableView.frame = self.view.bounds
}
and present the next view controller like this:
self.navigationController?.pushViewController(nextVC, animated: true)
and navigate back like this:
#IBAction func back(){
self.navigationController?.popViewControllerAnimated(true)
}
use autolayout. set top,bottom,leading and trailing constraints to it. and don't set frame of tableview like self.view.bounds
Try this code in viewWillAppear Method..
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated) // No need for semicolon
self.myTableView.frame = self.view.bounds
}
Related
I am using WKWebview to show my content. When I scroll webview, I would like to hide my navbar. I use below code and nothing is happen.
navigationController?.hidesBarsOnSwipe = true
Can someone tell me, how to do this.
Add top constraint for the webView with superview, set hidesBarsOnSwipe to true, and then load the URL (check screenshot for reference):
One of the ways through code is you can use the scrollview delegate method to identify if webview is scrolled. And there you can use navigationController?.setNavigationBarHidden(isHidden, animated: true).
Something like this:
set scrollview delegate in viewdidload self.webView.scrollView.delegate = self. And then use
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView.panGestureRecognizer.translation(in: scrollView.superview).y > 0
{
print("up")
navigationController?.setNavigationBarHidden(false, animated: true)
}
else
{
print("down")
navigationController?.setNavigationBarHidden(true, animated: true)
}
}
I tried implementing the simple one line of code shown below into my viewDidLoad in order to have my navigaion bar hide when a user swipes on my collectionview. However the action only works when i swipe from my navigation bar, no where else. I would like it to hide on swipe from my collection view which of course takes up most of the view.
A mini video of the issue
override func viewDidLoad() {
navigationController?.hidesBarsOnSwipe = true
}
Is the view controller embedded in the navigation controller?
Swift 4, Swift 5:
Hide your navigation bar when you scroll upside and similarly show when you scroll downside.
scrollViewDidScroll() method will get called every time when you scroll your CollectionView, TableView, ScrollView etc.
Try this code:
func scrollViewDidScroll(_ scrollView: UIScrollView) {
//Check the scroll direction here
if(scrollView.panGestureRecognizer.translation(in: scrollView.superview).y > 0) {
print("Show")
self.navigationController?.setNavigationBarHidden(false, animated: true)
self.navigationController?.setToolbarHidden(false, animated: true)
}
else {
print("Hide")
self.navigationController?.setNavigationBarHidden(true, animated: true)
self.navigationController?.setToolbarHidden(true, animated: true)
}
}
I have a UITableView embedded in a NavigationController. The cells each link out to a larger information ViewController. For UI purposes, I hide the Navigation Bar on the TableView and show it in the InfoViewController.
The problem I am experiencing is this: upon booting the app, the NavBar is successfully hidden on the TableView. The first time I tap into a cell and open an InfoViewController, the NavBar comes back as expected. I back out of that VC and into the TableView. Again, the NavBar is hidden, as expected. If I tap into another cell, the NavBar is not displayed as expected. NOTE: This happens even when I remove any code to hide the Navigation Bar.
Here are the relevant code snippets:
TableViewController (in ViewDidLoad()):
self.navigationController?.isNavigationBarHidden = true
InfoViewController:
override func viewWillAppear(_ animated: Bool) {
self.navigationController?.navigationBar.isHidden = false
super.viewWillAppear(animated)
}
Why would it work the first time, but not the second. Any help is appreciated!
For clarification:
App opens to TableView:
enter image description here
I click into the TableViewCell to Segue to InfoViewController:
enter image description here
I hit "Back" to go back to TableViewController. NavBar is still hidden. I click on the same cell:
enter image description here
EDITED: Messed up the TableViewController Code. Put = false instead of = true.
Also, I have one more thought, please someone check this for me. The TableViewController is inside a UIContainerView. It is almost as if when I hit "Back" I am exiting the NavigationController flow and I cannot get back in it.
Please try this code its working fine for hiding navigationBar
TableViewController
class TableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.isNavigationBarHidden = true
}
}
InfoViewController
class InfoViewController : UIViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.isNavigationBarHidden = false
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.navigationController?.isNavigationBarHidden = true
}
}
Simple hide navigationbar again when the view controller is appear again,
do below code in tableViewController:
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.navigationController?.isNavigationBarHidden = true
}
I'm trying to add TopView in my application, it will be the same for each views. I do it like this
let vcTopMenu = storyboard?.instantiateViewControllerWithIdentifier("TopMenu")
let win:UIWindow = UIApplication.sharedApplication().delegate!.window!!
win.rootViewController = vcTopMenu
win.makeKeyAndVisible()
But when I add other viewControllers (I do it transparent) I can see buttons of TopView, but I can't click on it. It's a code from TopView
override func viewDidLoad()
{
super.viewDidLoad()
print("loaded")
}
#IBAction func btn(sender: AnyObject)
{
print("do something")
}
I see "loaded", but clicking doesn't work, how can I click through view? Thanks!
If I understand your question correctly, you're placing a translucent/transparent UIView on top of another UIView with a button you want to press?
The topmost UIView by default receives the touches. More on this here.
It's not a very standard/practical way to do things, but if you absolutely must, check out this answer: https://stackoverflow.com/a/4010809/4396258
I have a ViewController called SourceViewController that is embedded in a NavigationController.
SourceViewController segues to DestinationViewController upon UITableViewCell selection.
I want to hide the navigation bar on SourceViewController, but display it on DestinationViewController in order to show the Back button.
So, in SourceViewController:
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.hidden = true
}
And in DestinationViewController:
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.hidden = false
}
However, when I tap "Back" in DestinationViewController to return to SourceViewController, the navigationBar reappears in SourceViewController
The next 'obvious' step would be to set navigationBar.hidden = false in viewDidAppear in SourceViewController, however this smells for many reasons: mainly DRYness but also when returning to SourceViewController, there is a delay in hiding the navigationBar, and it is visible for a split second.
How do I solve this problem?
I think this will work, hiding the navigation bar. before appearing/disappearing the view.
override func viewWillAppear(animated: Bool) {
navigationController?.navigationBarHidden = true
super.viewWillAppear(animated)
}
override func viewWillDisappear(animated: Bool) {
navigationController?.navigationBarHidden = true
super.viewWillDisappear(animated)
}
Check ViewController lifecycle Looking to understand the iOS UIViewController lifecycle .
When you start the program viewDidLoad is called and everything is ok, but when you go back from detailController, viewDidLoad is not called, just change this line (self.navigationController?.navigationBar.hidden = true) in viewWillApear and everything must be ok.