cemolcay / SlidingContainerViewController

An android scrollable tab bar style container view controller
MIT License
217 stars 41 forks source link

SlidingContainerViewControllerDelegate #12

Closed himanshupadia closed 7 years ago

himanshupadia commented 7 years ago

SlidingContainerViewControllerDelegates method are not called after slidingContainerViewController.delegate = self

could you please help me.

cemolcay commented 7 years ago

Updated! Please check out last version and let me know if it is working now.

himanshupadia commented 7 years ago

okay

himanshupadia commented 7 years ago

After library update, I have notice that only 1st method is got called, other two are not called. Let me know how to call this methods.

func slidingContainerViewControllerDidMoveToViewController(_ slidingContainerViewController: SlidingContainerViewController, viewController: UIViewController, atIndex: Int) {
       THIS DELEGATE METHOD IS CALLED
    }

func slidingContainerViewControllerDidShowSliderView(_ slidingContainerViewController: SlidingContainerViewController) {
       ## THIS DELEGATE METHOD IS NOT CALLED
    }

func slidingContainerViewControllerDidHideSliderView(_ slidingContainerViewController: SlidingContainerViewController) {
       ## THIS DELEGATE METHOD IS NOT CALLED
    }
cemolcay commented 7 years ago

if you call hideSlider and showSlider functions than their delegate methods get called.

himanshupadia commented 7 years ago

Actually I want to call below methods when I am leaving one tab and entering to other, but it's not. I have almost complete my work, due to this I am stuck. EX: a -> b or b->c or c->b or c->a

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

================================ slidingContainerViewController.hideSlider() slidingContainerViewController.showSlider() after writing about two lines, it hides tabbar but transition is working

cemolcay commented 7 years ago

Do your tabBarController is a child of a slidingContainerViewController or the other way around? If tabBarController is a child than viewDidAppear/viewDidDisappear methods are right place to hide/show slider. If you are using slidingContainerViewController as a tab of tabBarController than there are no way to show slider on other tabs unless they are also slidingContainerViewController. In that case you could probably share one slider between them.

himanshupadia commented 7 years ago

Actually my child controllers are not tabBarController, They are just UIViewController sub classes.

I have used 'SlidingContainerViewController' where I have added my childViewController.

let slidingContainerViewController = SlidingContainerViewController (
            parent: self,
            contentViewControllers: [Child_1, Child_2, Child_3],
            titles: ["Child_1","Child_2","Child_3"])
        view.addSubview(slidingContainerViewController.view)

When I load main controller, it load all childViewControllers, viewWillAppear and viewDidAppear once. But when I swipe to other childViewController it's doesn't call viewWillAppear and viewDidAppear.

So it's difficult to perform required operation when childviewcontroller will show/hide.

bhaumikdesai91 commented 7 years ago

@cemolcay First of all Nice work. I found this Library handy for my project.

@himanshupadia I have similar problem using this library. I am also not able to receive LifeCycle events on my Child UIViewController Subclasses after the initial setup is done. When I swipe to other viewController both present and next ViewController's Methods should get called.

I took a look at the source and I think there is some problem going on here..

for i in 0..<self.contentViewControllers.count {
      let vc = contentViewControllers[i]

      if i == index {
        vc.willMove(toParentViewController: self)
        addChildViewController(vc)
        vc.didMove(toParentViewController: self)
        delegate?.slidingContainerViewControllerDidMoveToViewController(self, viewController: vc, atIndex: index)
      } else {
        vc.willMove(toParentViewController: self)
        vc.removeFromParentViewController()
        vc.didMove(toParentViewController: self)
      }
    }

in the setCurrentViewControllerAtIndex(_ index: Int) Method.

Please take a look. I would be happy to help improve this Library.

Thanks.