hellosheikh
hellosheikh

Reputation: 3015

Problems with implementing SWRevealViewController in Swift

Hello I am new to iOS and trying to implement the SWRevealViewController. I have followed some tutorials and successfully implemented the SWRevealViewController in tutorial projects but I am struggling to implement the slide menu in my existing project.

So I have a storyboard in which there comes first a NavigationController which is a initial view controller and then comes sign,in or register screens. All connected to the navigationcontroller. After Sign in I am showing the homes screen in which the Hamburger menu is displaying.

By seeing the tutorials what I have tried is dragged a ViewController to storyboard and add a class SWRevealViewController. Then I dragged TableViewController and filled some rows with menu Items. Next, I have done is control-drag from SWRevealViewController to the Table view controller and chose reveal view controller set controller and named it sw_rear.

Now in tutorials for sw_front they have connected the SWRevealViewController to NavigationViewController which is directly connected to the Homescreen. But In my project it isn't as NavigationController is connected directly to signin. I have tried two things here. First I connected from SWRevealViewController to NavigationViewController through segue and it doesn't work and also I tried to embed another NavigtionViewController to homescreen and it still didn't work. I hope you understood my problem.

Code:

if revealViewController() != nil {
    print("check")
    menuButton.target = revealViewController()
    menuButton.action = "revealToggle:"
    view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}

Tutorial Link : http://www.appcoda.com/sidebar-menu-swift/

Upvotes: 2

Views: 778

Answers (2)

Barath
Barath

Reputation: 1754

This is a sample SWRevealViewController Slide Menu.

BMSlideMenu

BMSlideMenu

Upvotes: 0

Waris Shams
Waris Shams

Reputation: 1614

Actually the SWRevealViewController performSegueWithIdentifier not working so go into your SWRevealViewController Class and replace a method with this one

- (void)loadStoryboardControllers
{
    if ( self.storyboard && _rearViewController == nil )
    {
    //Try each segue separately so it doesn't break prematurely if either Rear or Right views are not used.
    @try
    {
        UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"yourMenuController storyboard Identifier"];
        SWRevealViewControllerSegueSetController *segue = [[SWRevealViewControllerSegueSetController alloc] initWithIdentifier:SWSegueRearIdentifier source:self destination:controller];
        [segue perform];
    }
    @catch(NSException *exception) {}

    @try
    {
        UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"your front viewcontroller storyboard Identifier"];
        SWRevealViewControllerSegueSetController *segue = [[SWRevealViewControllerSegueSetController alloc] initWithIdentifier:SWSegueFrontIdentifier source:self destination:controller];
        [segue perform];
    }
    @catch(NSException *exception) {}

    @try
    {
        [self performSegueWithIdentifier:SWSegueRightIdentifier sender:nil];
    }
    @catch(NSException *exception) {}
}

}

Upvotes: 0

Related Questions