Swift - Slide Menu Transtion between ViewControllers - ios

I'm working for a IOS9+ project using swift ,
using the same slide menu (Which is done programmatically) to translate between view controllers as shown in the link : Slide Menu and it working fine
the problem is it's using storyboard ID for each view controller in the function addChildView():
func addChildView(storyBoardID: String, titleOfChildren: String, iconName: String) {
let childViewToAdd: UIViewController = storyboard!.instantiateViewControllerWithIdentifier(storyBoardID)
tabOfChildViewController += [childViewToAdd]
tabOfChildViewControllerName += [titleOfChildren]
tabOfChildViewControllerIconName += [iconName]
menuToReturn.append(["title":titleOfChildren, "icon":iconName])
}
which is called in TransitionBetweenTwoViews function :
func transitionBetweenTwoViews(subViewNew: UIViewController){
//Add new view
addChildViewController(subViewNew)
subViewNew.view.frame = (self.parentViewController?.view.frame)!
view.addSubview(subViewNew.view)
subViewNew.didMoveToParentViewController(self)
//Remove old view
if self.childViewControllers.count > 1 {
//Remove old view
let oldViewController: UIViewController = self.childViewControllers.first!
oldViewController.willMoveToParentViewController(nil)
oldViewController.view.removeFromSuperview()
oldViewController.removeFromParentViewController()
}
print("After Remove: \(self.childViewControllers.description)")
}
that is called in the delegate of the BaseViewController Class
My problem is that I'm not using storyboard instead a nib file for each view controller , how could i do it without storyboard I have been searching for days to find solution but nothing work
Also the tableView of the menu is a table with sections
Please if you have any solution that could help it will be appreciated
or any other slide menu that work with nib files
Edit :
Slide Menu table View :
screen shot of slide menu with section so if i choose Flight Availability or Ticket Balance it will be like i choose home with index 0 how could i solve that ?

Related

Toolbar disappear after push

I have FormViewController that I made full programmatically with Eureka form builder (link). I dont have view controller in storyboard for that. Class name of that view controller is NewPasswordVC. When I click od add bar button I open NewPasswordVC with this code:
let newPasswordVC = NewPasswordVC()
self.navigationController?.pushViewController(newPasswordVC, animated: true)
I open NewPasswordVC but when I go back in root view controller my bottom toolbar disappear. Why? How to fix this?
This is storyboard:
This is my problem in gif:
Can't speak about Eureka specifically, but chances are the UIViewController being pushed in has hidesBottomBarWhenPushed set to true.
So I would look into setting it to false, which can be done programmatically.
The solution to my problem I found here: link
override func willMove(toParent parent: UIViewController?){
super.willMove(toParent: parent)
if parent == nil{
self.navigationController?.isToolbarHidden = false
}
}

navigating through desired views (while skipping some views) using UINavigationBar back button

I am using a UICollectionView to show a list of images.
1)By clicking on any cell the image and some description about it is displayed in the resulting view controller(using a push segue).
2)When i swipe from the left/right edge(using PanGesture) i need to display the details of the previous/next image in the collection view.
3)But the back button of the navigation bar has to take me back to the collection view and not to the previous displayed details (shown by the PanGesture).
I know how to get 1 and 2 done but don't have a concrete idea to get the 3rd job done.
Any help would be appreciated.
You can find your desired UIViewController in your navigation stack using for loop. Try this. This is in Swift
for (var i = 0; i < self.navigationController?.viewControllers.count; i++) {
if (self.navigationController?.viewControllers[i].isKindOfClass(YourViewController) == true) {
println("is sw \(self.navigationController!.viewControllers[i])")
(self.navigationController!.viewControllers[i] as! YourViewController)
self.navigationController?.popToViewController(self.navigationController!.viewControllers[i] as! YourViewController, animated: true)
break;
}
When you navigate from one view to another (e.g. by showing a detail view of your images one after the other, then all these views are internally piled up as a stack.
Thus, if you want to jump directly to a view somewhere in between this stack (e.g. the collection view), then you can use the Unwind Segue.
In your case it should work like this:
First, in your collection view (i.e. your back button destination) you need to implement a UIStoryboard Segue as follows
#IBAction func myGoBackPoint(segue: UIStoryboardSegue) {
println("Jump directly back here from any other view")
}
Then, in the storyboard of your detail view you ctrl-drag directly to top rightmost Exit marker and choose the previously created back button destination:
In the code of the detail view implement the "go back instruction"
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "My Unwind Segue" {
if let myUnwindSegue = segue.destinationViewController as? MyCollectionViewController {
// prepare for segue
}
}
}
Hope this helps.
Finally after researching a lot i found that using a collection view with each cell taking up the whole screen is the best way to go about solving this issue.
Thankyou

In Swift How to change the selected tab bar

I am new to swift programming and I have a Tabbed application with 2 UITabBar items , I want that when user taping the second tab, application set the selected tab index to 0 and move user to the first tab. I tried this code in my SecondViewController.swift's viewDidLoad :
self.tabBarController?.selectedIndex = 0
but it doesn't work.
This works:
override func viewDidAppear() {
self.tabBarController?.selectedIndex = 0
}
See this answer for a good explanation of viewDidLoad() vs. viewDidAppear.
Relevant excerpt:
This is where you want to perform any layout actions or do any drawing in the UI - for example, presenting a modal view controller

"Default" view in UITabBarController

I have a UITabBarController with 5 NavigationControllers, embedded in it as tabs (similar to picture 1 below). So, the question is: I want to show the table view (or any another view) as a "default" view, when the TabBarController is shown. I.e., show the view (view controller), which is not embedded in TabBarController and make any tab selected. I apologize for such explanation, better watch on picture #2 below. I'm using latest version of XCode and Swift in my project. And for interface I'm using storyboard
You can determine which tab to select in the first (initial) viewController.
Note: Swift 3
override func viewDidLoad() {
super.viewDidLoad()
self.tabBarController?.selectedIndex = 1
}
Note that by default the first selected viewController is at 0 index (self.tabBarController?.selectedIndex = 0)

Side menu with dynamic table cell will navigate page but with navigation controller coming as nil

I have create sidemenu using this.
But the difference is only i have used dynamic UITableViewCell instead of static.
Now i face navigation issue while click on side menu item.
I have used navigation code like:
dispatch_async(dispatch_get_main_queue()) {
let propertyListing = self.storyboard?.instantiateViewControllerWithIdentifier("PropertyListing") as! PropertyListingController
self.showViewController(propertyListing as UIViewController, sender: propertyListing )
}
It will navigate the page but navigation controller will be nil after that.
What can be the issue ? Any suggestion will be most appreciate.
Rather than using a "show", you need to push the new view controller.
self.navigationController.pushViewController(propertyListing, animated: true)

Resources