SWRevealViewController icon indicating copy to clipboard operation
SWRevealViewController copied to clipboard

From ViewController navigate back to SWRevealViewController Front Page

Open jefferyleo opened this issue 9 years ago • 42 comments

screen shot 2015-11-30 at 4 29 48 pm

As you can see in the picture, there're 3 controllers at the bottom which are (HomeTableViewController, NavigationViewController and NewsViewController)

HomeTableViewController is the Main Page which I'm using the SWRevealViewController and set it as a front page. (sw_front)

After I've selected a row in HomeTableViewController, it can navigate to NewsTableViewController. However, I've added a back button in the NewsViewController to navigate back to the previous page which is HomeTableViewController, I'm not manage to do that with this code.

In the HomeTableViewController navigate to NewsViewController by selected a row

@IBAction func btnBack(sender: AnyObject) { let home = HomeTableViewController() self.presentViewController(home, animated: true, completion: nil) } In the NewsViewController press back button back to previous page

@IBAction func btnBack(sender: AnyObject) { let home = HomeTableViewController() self.presentViewController(home, animated: true, completion: nil) } If I pressed the back button in the NewsViewController, this error appeared.

fatal error: unexpectedly found nil while unwrapping an Optional value self.revealViewController().rearViewRevealWidth = 200 This code has an error and is located in the HomeTableViewController. I hope that someone could help me on this. Thank you.

jefferyleo avatar Nov 30 '15 09:11 jefferyleo

Delete the navigation controller between Home and News and choose a push segue from Home to News. No needs func btnBack anywhere.

iDevelopper avatar Nov 30 '15 10:11 iDevelopper

I hope I understood what you want to do. I modified the example RevealControllerStoryboardExample2 accordingly.

https://www.dropbox.com/s/srptix9dddcwrn3/SWRevealViewController-master.zip?dl=0

iDevelopper avatar Nov 30 '15 11:11 iDevelopper

@iDevelopper Thanks a lot! I did it man. Million of thanks, appreciate. :+1:

jefferyleo avatar Dec 01 '15 04:12 jefferyleo

https://github.com/iDevelopper/PBRevealViewController

iDevelopper avatar Jul 22 '16 11:07 iDevelopper

@iDevelopper Hello, Patrick. It seams this solves the problem with segueing back, but what do i do if navigation bar disappears please? Thank you in advance.

NonAtomicFunk avatar Jan 03 '17 15:01 NonAtomicFunk

Not anderstand. Why does the navigation bar disappear? You can't push a view controller without a navigation controller.

iDevelopper avatar Jan 04 '17 08:01 iDevelopper

in case i'm deleting NavController between ViewCountroller i m segueing to, and SWR sideMenu -> UINavigationItem i've created disappears in ViewController

NonAtomicFunk avatar Jan 04 '17 09:01 NonAtomicFunk

You must have a navigation controller for that:

SWR -> UINavigationController -> UIViewController -> UIViewController etc...

iDevelopper avatar Jan 04 '17 09:01 iDevelopper

Yes, this is exact pattern i'm using. But I got lost :/ Please explain. So i have navigation controller before ViewController, and SW sideMenu segue leads to this NavC. And you've advised to delete it, in order to solve "navigate back" problem.

Please explain

NonAtomicFunk avatar Jan 04 '17 10:01 NonAtomicFunk

I advised to delete one navigation controller (between home and news) because @jefferyleo had already one before home.

iDevelopper avatar Jan 04 '17 15:01 iDevelopper

I see. But i'm facing the merely the same problem with segueing back to SWR.

If i may describe my problem in more details, it goes like this: my user logs in at separate viewController -> SWRevealViewController -> sw_front sideMenuLeads segues lead to -> UINavController -> ViewContoller_Z -> VC_Y

So, the problem is - i can't go back to SW_Front_VC from VC_Z

Please advise what am i doing wrong.

p.s. Even if i try method "present(SWR...." it gives me black Screen. p.p.s. in case of sucessfull seguey to SW_Front - i have errors with all the objects that contain parsed values.

NonAtomicFunk avatar Jan 04 '17 15:01 NonAtomicFunk

Do you mean come back to the first front view controller, not ViewController_Z?

iDevelopper avatar Jan 04 '17 16:01 iDevelopper

Yes, from the very first ViewControllers, that SideMenu segues to.

NonAtomicFunk avatar Jan 04 '17 16:01 NonAtomicFunk

I think you should use UINavigationControllerDelegate for that. I will post a sample.

iDevelopper avatar Jan 04 '17 16:01 iDevelopper

Thank you. I'll be waiting. Thank you again

NonAtomicFunk avatar Jan 04 '17 16:01 NonAtomicFunk

Hi @Lexx0 ,

What about this sample?

SWPopToFrontSwift.zip

iDevelopper avatar Jan 05 '17 09:01 iDevelopper

Sorry for being newb, but where should i look for solution here, please?

NonAtomicFunk avatar Jan 05 '17 14:01 NonAtomicFunk

I'm not sure to understand your question. It works for you or not? See in RearTableViewController:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)

iDevelopper avatar Jan 05 '17 14:01 iDevelopper

Um, i have no problem with getting back to FrontVC via SWmenu. I'm experiencing problem with getting back via "back button" on navigaitonBar. I've implemented your method on my "backBtn", but it gives no result.

Thanks again for your time.

NonAtomicFunk avatar Jan 06 '17 14:01 NonAtomicFunk

There is nothing special to go back. Because we use the navigation controller of the front view controller, it comes back automatically.

iDevelopper avatar Jan 06 '17 14:01 iDevelopper

so, what method should i use to load SW_Front? "revealVC" - doesn't work. Please advise.

NonAtomicFunk avatar Jan 10 '17 06:01 NonAtomicFunk

Sorry but regarding my sample I don't understand your question and/or your problem. Can you show a bit of code?

iDevelopper avatar Jan 10 '17 08:01 iDevelopper

here it goes.

"class CardsVC: UIViewController, UITableViewDelegate, UITableViewDataSource { @IBOutlet weak var menuBtn: UIBarButtonItem! @IBOutlet weak var backBtn: UIBarButtonItem!"

and in viewDidLoad " menuBtn.target = self.revealViewController() menuBtn.action = #selector(SWRevealViewController.revealToggle(_:)) revealViewController().tapGestureRecognizer() revealViewController().panGestureRecognizer()"

So my question is, how can i return to the SW front VC via custom back Button on nav bar. Thank you

NonAtomicFunk avatar Jan 10 '17 10:01 NonAtomicFunk

Then you have two buttons. menuBtn for opening left side view (sw_rear). And an other one (backBtn). Create an action and call popViewController if your CardsVC has been shown with the frontVC'navigationController.

iDevelopper avatar Jan 10 '17 12:01 iDevelopper

Could you please explain " if your CardsVC has been shown with the frontVC'navigationController"? How should i connect CardsVC with frontVC'navigationController? Please advise. The following method gives no result :(

"backBtn.target = self backBtn.action = #selector(goBack)" .... "func goBack(_ sender: Any?){ _ = navigationController?.popViewController(animated: true) }"

NonAtomicFunk avatar Jan 10 '17 13:01 NonAtomicFunk

You can that in my sample I OtherViewController or SettingsViewController are shown with the FrontTableViewController'navigationController, then there is a back button to come back:

2017-01-10_14-29-36

Then there is a back button:

2017-01-10_14-34-00

Do you want to have another button to show the side menu?

iDevelopper avatar Jan 10 '17 13:01 iDevelopper

i've deleted default navigation "back button" with following code "self.navigationItem.hidesBackButton = true", coz it overlapped my "menu button" on the left

NonAtomicFunk avatar Jan 10 '17 18:01 NonAtomicFunk

I really don't understand what you want to do, sorry

iDevelopper avatar Jan 10 '17 18:01 iDevelopper

I need to go back to SW_front, be using custom "back button" on the right of navigation bar.

NonAtomicFunk avatar Jan 11 '17 07:01 NonAtomicFunk

Ah ok, then why do you want to push the controllers with navigation controller and not with reveal view controller ?

iDevelopper avatar Jan 11 '17 07:01 iDevelopper

    @IBAction func back(_ sender: UIBarButtonItem) {
        
        let nc = revealViewController().rearViewController as? UINavigationController
        let frontNVC = (nc?.topViewController as? RearTableViewController)?.frontNVC
        _ = frontNVC?.popViewController(animated: true)
    }

iDevelopper avatar Jan 11 '17 07:01 iDevelopper

in case i'm using pushSegues, instead of "SWRevealViewControllerSeguePushController" - i'm getting error on following code line "revealViewController().tapGestureRecognizer()"

how can i contact you in private, in order to share some more code, please?

NonAtomicFunk avatar Jan 11 '17 12:01 NonAtomicFunk

@iDevelopper I am having a similar issue with my reveal view controller but kind of confused on what to do. I am a newbe so wanted to make sure Im doing everything properly.

I want to be able to go back to the main view controller from my side menu profile view controller using a back button. I saw your SWPopToFrontSwift 2 file but my reveal controller is set up a bit different.

So when I click on my profile table cell I go into My profile view controller. From there i want to go back to my main view controller not the side menu.

Appreciate any help I can get. thank you

drmikeb avatar Sep 03 '17 06:09 drmikeb

@drmikeb ,

Test the #721 sample and give me a callback.

iDevelopper avatar Sep 03 '17 06:09 iDevelopper

@iDevelopper,

I set it up exactly the same as in #721. Im getting a sigabrt error when I click on the left menu on simulator. Any ideas why? Thank you for your quick reply

drmikeb avatar Sep 05 '17 20:09 drmikeb

@iDevelopper, I finally figured it out. How would I change the color of the text on the slide out menu?

drmikeb avatar Sep 06 '17 00:09 drmikeb

    cell.textLabel?.textColor = UIColor.red

iDevelopper avatar Sep 06 '17 05:09 iDevelopper

Thank you. I want to include a map that shows local places(such as restaurants and bars) and be able to change to a list view of those places back from the map. Would you be able to point me in the right direction? I have gotten the google maps api but don't know where to begin to implement this.

drmikeb avatar Sep 08 '17 02:09 drmikeb

Hello,

Start here : https://developers.google.com/maps/

And there are a lot of samples.

Patrick BODET

De : drmikeb [email protected] Répondre à : John-Lluch/SWRevealViewController [email protected] Date : vendredi 8 septembre 2017 à 04:00 À : John-Lluch/SWRevealViewController [email protected] Cc : Courriel BODET [email protected], Mention [email protected] Objet : Re: [John-Lluch/SWRevealViewController] From ViewController navigate back to SWRevealViewController Front Page (#516)

Thank you. I want to include a map that shows local places(such as restaurants and bars) and be able to change to a list view of those places back from the map. Would you be able to point me in the right direction? I have gotten the google maps api but don't know where to begin to implement this.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

iDevelopper avatar Sep 08 '17 08:09 iDevelopper

How can I use a UIAlert to open the viewcontroller, without using the SWReveal Menu?

famictech2000 avatar Jul 29 '18 21:07 famictech2000

You should open a new issue for that as your question is not relative to this one, but is what you need.

iDevelopper avatar Jul 30 '18 07:07 iDevelopper