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

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)

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
}
}

Custom NavigationBar in swift

I am very much new to swift and ios so i need my doubts to be cleared for the below concept
I have created a view with a button having background image of back arrow and on button action i am going back to the previous controller which is the Login, is it safe to do it this way instead of using NavigationController??
#IBAction func onBackPressed(sender: AnyObject) {
let aaa : Login =
self.storyboard?.instantiateViewControllerWithIdentifier("Login")
as! Login
self.presentViewController(aaa, animated: true, completion: nil)
}
Thanks
Navigation controller is best when you want to push to next View Controller.
(i.e) Navigation Controller ->View Controller ->View Controller[for Push].
So my suggestion is if you want to come back to previous view controller use Navigation Controller
When you want to present a new View Controller that time no need.

View controller view getting misplaced when navigating back to the home screen of UITabbarController

I have a tabbarcontroller in my application and have added view controllers with the help of storyboard and segues,
When i am in the second tabbar item I have a table view embedded with a navigation controller filled with usernames and on top I have a hamburger icon, I select a particular item from the table list present in the hamburger icon and navigate to the details view controller I have used segues and given below is the code for the same
self.performSegueWithIdentifier("MY_DETAIL_SEGUE_NAME", sender: nil)
MY_DETAIL_SEGUE_NAME is actually a custom push segue of the SWRevealViewControllerSeguePushController, the push is working fine and i am able to navigate to the details screen.
The Problem: Since I am in the second tabbar item on the hit of back button i need to show the inital view / home view controller of the second tabbar item which is the friend view list, so on the back button i have written the below code in the detail screen
#IBAction func moveBackToController(sender: AnyObject) {
self.performSegueWithIdentifier("showFriendListPage", sender: nil)
}
showFriendListPage: This is a custom segue to the firendlist page using the SWRevealViewControllerSeguePushController and is pointed to the tabbarcontroller
To highlight the second tabbar item i have used the below code written in the detail screen
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
let objParentTabbar = segue.destinationViewController as! ParentTabbarController
if segue.identifier == "showFriendListPage" {
objParentTabbar.selectedIndex = 1
}
}
What happening here is when i navigate back to the home screen of the second tabbar item my view is distorted i.e. the UI elements are not placed in a correct order which they were when i first went to the second tabbar
Note: All my view controllers are embedded inside the navigation controller so the structure is
TabbarController----->NavigationController------>ViewController
Please suggest where I am going wrong and what needs to be done to resolve this, my only struggle is the view getting distorted and i dont really know why is this happening.
Call the view your controller via code in your application should do the trick
objParentTabbar.selectedViewController?.viewWillAppear(true)

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

Back button doesn't appear in navigation bar

I'm having trouble understanding the way view controllers are presented and how to navigate between them in swift. I have a contact list, when you click on one contact it opens the related conversation, but it doesn't show any back button to the conversation list. My storyboard is :
Contact List -> Navigation Controller -> Messages Controller
There is no navigation controller before contact list because it messes up with a sliding menu.
Here is my code:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "ShowConversationFromSelectedContact" {
let nav = segue.destinationViewController as! UINavigationController
let cdtvc = nav.topViewController as! MessageViewController
cdtvc.currentConversation = openConversation
}
}
More generally if you could explain or have any good ressource about the way stack of controllers work and how to navigate between them it would be great, I read a bunch articles but it's still unclear.
Re-arrange it so it is Nav Controller -> Contact list -> Message controller, and use push segues (if you're using swift 1.2+, they're called Show segues).
Inside prepareForSegue: you don't need to do anything else besides setting the contact id (or whatever data you need to pass) to the message controller.
Edit:
For a sliding menu, I suggest the following navigation model:
The Storyboard ViewControllers hierarchy goes
Nav Controller --root segue--> Contact List VC --show segue--> Message VC
Sliding menus are usually to present Top Level Views. Your Contact List VC is a top level view. Since it is also the root VC, you can use self.navigationItem.leftBarButtonItem to assign a button to show your sliding menu.

Resources