Regarding Side menu with Tabbarcontroller - ios

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.

Related

Modally presented view controller dismisses by itself on touching the view in the upper side of the screen

I have a view controller which has a table view and in the didSelectRowAt indexPath I instantiate the destination view controller, embed it into a navigation controller and present it... here is some code
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let destVC = DetailVC(frame: self.view.frame)
//passing data to the destVC ...
destVC.modalTransitionStyle = .partialCurl
let nav = UINavigationController(rootViewController: destVC)
present(nav, animated: true, completion: nil)
}
Working like a charm so far. When the detail VC appears everything's great, the tableView works perfectly, the leftBarButtonItem dismisses the detailVC as it should, but whenever I press anywhere on the upper side of the screen the detail view somehow automatically dismisses itself, which I don't want. I'm gonna leave a link to an image to see exactly what part of the screen automatically enables the dismiss function:
http://prntscr.com/kaibxg
I've been struggling with this and I didn't find any solution. I don't know why this is happening. When I use the pushViewController function, the detail VC is all right and is not popping itself out, but the thing is I really need to use the .partialCurl transition animation. I tried to find a way to somehow use .partialCurl when pushing the VC but I didn't find anything about that. Any help, answer, question is more than welcomed and appreciated. Thank you all in advance.

Instantiate view controller many ties inside the same tab bar item

I have slide menu based on tableView. Also I have tab bar created on IB.
First item on tab bar is like Home page. By defaut when run app that item display home screen. When select one of items from menu it should open on the same view as Home page.
//part of the code from menu item responsible to select Home page tab bar item
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
ContainerVC.tabBarViewController?.selectedIndex = 0
}
//viewWillAppear function on separated view controller
override func viewWillAppear(_ animated: Bool){
super.viewWillAppear(true)
let vc = self.storyboard?.instantiateViewController(withIdentifier: "DynNews")
self.navigationController?.pushViewController(vc!, animated: true)
}
This works only once, when start app. Later on app showing up just Home page. This is because tab bar load view only once and then selecting tab index does not call viewWillAppear but I do not know how to solve this.
You can achieve this functionality by number of different approaches.
To navigate inside a tabbar you should embed your controllers in a navigation controller.
This image will help you understand.
Further more you can take help from this link and this link. Also you can check out number of libraries on cocoacontrols and github for the require functionality. For better understanding I would recommend apple documentation.

Embed Material CardTableView in UINavigationController

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)

Hide delete button when tap back button in EKEventViewController

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.

Proper segue flow

I am looking for the best-practice method of doing the following:
I have two TabBarController views embedded in a NavigationController and one which I don't want to include as a tab but is embedded in a NavigationController:
FeedView (TableViewController)
VenueView (CollectionViewController)
SelectView (ViewController)
In VenueView (2), I have the following code to bring up SelectView (3):
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let selectVC: SelectViewController! = self.storyboard?.instantiateViewControllerWithIdentifier("selectVC") as! SelectViewController
selectVC.currentVenue = venueItems[indexPath.row]
presentViewController(selectVC, animated: true, completion: nil)
}
This segue works, however SelectView(3) doesn't have a navigation bar at the top although it is embedded in a separate NavigationController. If I hook it up to the other NavController in the IB, it adopts/becomes the third tab in the BarTabController. I don't want that.
How do I hook it up so that there is a NavBar (with a back button that will go back to either view) but no Tab?
Also, there is a button on SelectView(3). When this button is tapped I'd like it to segue to FeedView(1) - while persisting some data ie 'pushing into the feed'. What kind of segue should I use for this? I've tried many combinations and ran into some strange bugs and I find View management very confusing.
Storyboard image below for reference
Views are in order from top to bottom (1-3):
In order to do this you need to fix your problem, you need to present the navigation controller which contains SelectView but not SelectView itself as you do now.
You should set a storyboard identifier to your 3'rd navigation controller and apply this change:
let selectNavigationController = self.storyboard?.instantiateViewControllerWithIdentifier("selectNavigationController") as! UINavigationController
let selectVC = selectNavigationController.topViewController as! SelectViewController
selectVC.currentVenue = venueItems[indexPath.row]
presentViewController(selectNavigationController, animated: true, completion: nil)

Resources