I have using EkEventViewController to view event in my app.
My code should be like below:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let eventViewController = EkEventViewController()
eventViewController.delegate = self
eventViewController.allowsEditing = true
eventViewController.allowsCalendarPreview = true
eventViewController.hidesBottomBarWhenPushed = true
eventViewController.event = self.events[indexPath.row]
self.navigationController?.pushViewController(eventViewController, animated: true)
}
When I tap back button from EkEventViewController. The delete button bar should not hide. How to hide or remove delete bottom button bar
Based on your question, I presume that the 'delete' button or border retains after tapping on back button from EKEventViewController. The delete button from EKEventViewController is actually from toolbar in navigationController. You can hide the toolbar via setToolbarHidden(_ hidden: Bool, animated: Bool)
To do so, you have to initialize a new class with the subclass of EKEventViewController and push your view controller to it. Then, add the line below in your viewWillDisappear of the new class:
self.navigationController?.setToolbarHidden(true, animated: false)
Do note that this solution is based on assumption that you do not have existing toolbar prior to calling the EKEventViewController.
Related
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 have a scenario like I am using AKSideMenu and Tabbarcontroller both have same items like home, profile etc means home can access from tab bar as well as from side menu.My problem is that access from tab bar is fine but if I select Home from side menu then tab bar item is select correctly but view controller along with tab bar is not correct(selecting home from side menu display selected home tab bar but view controller is profile view or some random).
Please find code below.
public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
self.sideMenuViewController!.contentViewController = nil
switch indexPath.row {
case 0:
self.sideMenuViewController!.setContentViewController(getLandingStoryBoard().instantiateViewController(withIdentifier: "MyTicketsViewController"), animated: true)
self.tabBarController?.selectedIndex = 0
self.sideMenuViewController!.hideMenuViewController()
case 1:
self.sideMenuViewController!.setContentViewController(getHistoryStoryboard().instantiateViewController(withIdentifier: "BiddingHistoryViewController"), animated: true)
self.tabBarController?.selectedIndex = 1
self.sideMenuViewController!.hideMenuViewController()
}
}
I think your issue is you're setting the content view controller to a new vc instantiated from the storyboard instead of setting it to the selected view controller of the tab bar controller.
try
self.tabBarController!.selectedIndex = 0
self.sideMenuViewController!.setContentViewController(self.tabBarController!.selectedViewController!, animated: true)
Either that or the content view controller should always be the tab bar controller.
I am trying to setup a master/detail view with CardTableView as my root and am having trouble implementing
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
//code
}
I want to use a self.navigationController?.pushViewController so that the detail view can easily come back to the table view. However when I try to embed this in a Navigation controller I get a strange looking title bar:
This is my view hierarchy:
let tabs = AppPageTabBarController(viewControllers:[InvitedViewController(), CoordinatingViewController(), PastViewController()])
let toolbar = AppToolbarController(rootViewController: tabs)
let navigationController = UINavigationController(rootViewController:toolbar)
let fabController = AppFABController(rootViewController: navigationController)
let snackBarController = AppSnackbarController(rootViewController:fabController)
let navDrawer = MyTeeUpsViewController(rootViewController: snackBarController, leftViewController: NavDrawerContainerController())
self.present(navDrawer, animated: true)
Wondering if there are any alternatives to this approach
By default, UINavigationController shows its own navigation bar above your view controller(s). In your screenshot, it's the large, light-colored bar above your views. If you don't want this, you'll have to set it so when you instantiate the navigation controller:
// You may want to animate it if you hide/show it after it's onscreen
navigationController.setNavigationBarHidden(true, animated: false)
Short story:
Going from UIPageViewController (that presents proper DetailViewController) to UITableViewController, then changing (on didSelectRowAtIndexPath) the DetailViewController of the UIPageViewController and navigationController?.popViewControllerAnimated(true), displays proper UIPageViewController with changed DetailViewController but the whole view is moved down by the height of the navigationBar. Clicking on the screen sends it under the bar (where it should be).
Long story:
I embedded UIPageViewController into UINavigationController. Navigation bar translucent
I created a DetailViewController in my storyboard with a scrollView inside it.
I created custom function in the UIPageViewController to return desired UIViewController
func viewDetailViewController(index: Int) -> DetailViewController? {
if let storyboard = storyboard, page = storyboard.instantiateViewControllerWithIdentifier("DetailViewController") as? DetailViewController {
// Setting the page variables that it stores
return page
}
return nil
}
I set up a code (also in UIPageViewController):
override func viewWillAppear(animated: Bool) {
if let viewController = viewDetailViewController(currentIndex) {
setViewControllers(
[viewController],
direction: .Forward,
animated: false,
completion: nil)
}
}
Then I setup an bar button item to and in the storyboard I connected it to so it perform segue to UITableViewController. I want to pop a viewContorller on cell click so:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
self.pageViewController.currentIndex = indexPath.row
navigationController?.popViewControllerAnimated(true)
}
When the view is popped the new view of the UIPageViewController is replaced, the pages work well and everything is great except one thing. The whole view is moved down by the height of the navigationbar. What's even more strange is that (just) tapping on the screen sets the scrollView under the navigationbar (where it should be)
I have also noticed that not only the scrollView is moved down, but what is actually moved down is UIView that contains an UIView that contains the scrollView.
What might be causing this?
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let memeShowViewController = self.storyboard!.instantiateViewControllerWithIdentifier("ShowMeme") as! MemeShowViewController
memeShowViewController.memeImage = appDelegate.memes[indexPath.row].memeImage
self.navigationController!.presentViewController(memeShowViewController, animated: true, completion: nil)
}
So I have a tableview that has a nav controller embedded in it and when I present the memeShowViewController modally I was wondering why the view of the memeShowViewController has a black background color when I didn't change it to be black.
In storyboard:
In simulator
Right now I'm just adding a navigation bar to the segue-ed view controller, I was wondering if there is a better way to do as the only functionality I need from the navigation bar is for the done button to segue back to the tableView.
The background window has a black background so if your app doesn't cover any part of the window (or alpha = 0) you'll see that black background.