iDevelopper / PBRevealViewController

A UIViewController subclass for revealing a left and/or right view controller above or below a main view controller.
MIT License
80 stars 16 forks source link

Problem with Right Menu. #45

Closed FedericoSub closed 6 years ago

FedericoSub commented 6 years ago

Hi I'm having trouble with code:

if let indexPath = self.collectionView?.indexPathForItem(at: sender.location(in: self.collectionView)) { let num = indexPath.last

        if (imgBuddyArray[num!].nome) == "Aggiungi" {
               print(imgBuddyArray[num!].nome)

            **let mainStoryboard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            let desController = mainStoryboard.instantiateViewController(withIdentifier:     "BuddyTableViewController") as! BuddyTableViewController
            let newFrontViewController = UINavigationController.init(rootViewController:desController)
            revealViewController()?.pushMainViewController(newFrontViewController, animated: true)**

        }

    } else {

    }

This is for open BuddyTableViewController when I tapped un "Aggiungi"

schermata 2018-02-20 alle 10 10 40

This is BuddyTableViewController:

schermata 2018-02-20 alle 10 12 05

This VC is opened correctly from the right menu when I tapped on "Amici" using the same code above, but the first VC doesn'work

schermata 2018-02-20 alle 10 11 46

any suggest ?

thanks

iDevelopper commented 6 years ago

Do you mean that when you tap on Home nothing happens?

FedericoSub commented 6 years ago

No , when I tapped on button "Aggiungi" (on bottom side) tap

I'd like to open the BuddyTableViewController. https://user-images.githubusercontent.com/35109594/36415611-d34a4760-1626-11e8-80cc-5d569f0c1d21.png

On tap of button I used the same code that works un menu (tap on Amici) but nothing happens.

amici

FedericoSub commented 6 years ago

If you need I can attach all code..

iDevelopper commented 6 years ago

Yes if you can, because it is very difficult to help without it.

FedericoSub commented 6 years ago

can I drag some file in .zip here?

FedericoSub commented 6 years ago

in ProfiloROTableViewController you can find this func that if you Tapped on circle image I'd like open BuddyTableViewController

@objc func tap(sender: UITapGestureRecognizer){

    if let indexPath = self.collectionView?.indexPathForItem(at: sender.location(in: self.collectionView)) {
        let num = indexPath.last

        if (imgBuddyArray[num!].nome) == "Aggiungi" {
               print(imgBuddyArray[num!].nome)
            let mainStoryboard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            let desController = mainStoryboard.instantiateViewController(withIdentifier: "BuddyTableViewController") as! BuddyTableViewController
            let newFrontViewController = UINavigationController.init(rootViewController:desController)
            revealViewController()?.pushMainViewController(newFrontViewController, animated: true)
        }

    } else {

    }

}

Archivio 2.zip

iDevelopper commented 6 years ago

Could you attach the project, not only the swift files? Archive the folder that contains the xcodeproj file.

FedericoSub commented 6 years ago

can I send with wetransfer ? is too big .

can I have your email?

iDevelopper commented 6 years ago

patrick.bodet4@wanadoo.fr

FedericoSub commented 6 years ago

sent with wetransfer thanx

iDevelopper commented 6 years ago

Ok, pushMainViewController is for pushing a new controller from left or right side view controller. In this case you want to replace the main view controller. Use setMainViewController instead of pushMainViewController:

    @objc func tap(sender: UITapGestureRecognizer){
        if let indexPath = self.collectionView?.indexPathForItem(at: sender.location(in: self.collectionView)) {
            let num = indexPath.last

            if (imgBuddyArray[num!].nome) == "Aggiungi" {
                   print(imgBuddyArray[num!].nome)
                let mainStoryboard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
                let desController = mainStoryboard.instantiateViewController(withIdentifier: "BuddyTableViewController") as! BuddyTableViewController
                let newFrontViewController = UINavigationController.init(rootViewController:desController)
//                revealViewController()?.pushMainViewController(newFrontViewController, animated: true)
                revealViewController()?.setMainViewController(newFrontViewController, animated: true)
            }

        } else {

        }
    }
FedericoSub commented 6 years ago

thanks Patrik works fine now .....sorry for my stupid question :-) I'm a beginner with swift Thanks again

iDevelopper commented 6 years ago

Ok, there is no stupid question! Most important is that it works :-)

FedericoSub commented 6 years ago

Just last help....how can I close the menu when is open with gesture ? thanks

iDevelopper commented 6 years ago

In MainTableViewController.swift, remove:

        self.revealViewController()?.panFromLeftBorderWidth = 50
    override func viewDidLoad() {
        super.viewDidLoad()

        // Keep a reference to this controller
        let rightController = self.revealViewController()?.rightViewController as! UINavigationController
        let rightTableViewController = rightController.topViewController as! MenuViewController
        rightTableViewController.navMainController = self.navigationController
        //

        rightButton.target = self.revealViewController()
        rightButton.action = #selector(PBRevealViewController.revealRightView)

        self.revealViewController()?.isRightPresentViewOnTop = false
        self.revealViewController()?.rightViewRevealWidth = 210

        self.revealViewController()?.delegate = self

        //self.revealViewController()?.panFromLeftBorderWidth = 50
        self.revealViewController()?.panFromRightBorderWidth = 50

        updateView()

        //MARK make navbar trasparent
        let bar:UINavigationBar! =  self.navigationController?.navigationBar
        bar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
        bar.shadowImage = UIImage()
    }
iDevelopper commented 6 years ago

Other things: Don't forget to always call the superview methods:

    super.viewDidDisappear(animated)
    super.viewWillAppear(animated)

For example:

    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)

        ref.removeObserver(withHandle: handle)
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        if let user = Auth.auth().currentUser {

            useridIniziale = user
            let newUser = Database.database().reference().child("users").child((useridIniziale?.uid)!)
            newUser.updateChildValues(["Token": Messaging.messaging().fcmToken ?? ""])

            news.removeAll()

            leggiDati()

            tableView.reloadData()
        }
    }
FedericoSub commented 6 years ago

:-) thanks