SWRevealViewController - RightViewController

爱⌒轻易说出口 提交于 2019-11-28 01:22:11

here is the sample project , this is working fine I worked out for your self, the download link is

https://www.sendspace.com/file/0l2ndd

after downloaded the project u want to delete the project , use this link

https://www.sendspace.com/delete/0l2ndd/1b1bd537ad852b2fdea9b9a0cce3390f

here u were need the right swipe on the front view controller , add the UIBarButtonItem in the particular view Controller

    @property (strong, nonatomic) IBOutlet UIBarButtonItem *rightIcon;   //this is for left bar button Item
    @property (nonatomic) IBOutlet UIBarButtonItem* revealButtonItem;  //this is for right bar button Item

and add the some functions is View DidLoad

- (void)viewDidLoad
{
[super viewDidLoad];

 //action for left Swipe
[self.revealButtonItem setTarget: self.revealViewController];
[self.revealButtonItem setAction: @selector( revealToggle: )];
[self.navigationController.navigationBar addGestureRecognizer:  self.revealViewController.panGestureRecognizer];

//action for Right Swipe
[self.rightIcon setTarget: self.revealViewController];
[self.rightIcon setAction: @selector( rightRevealToggle: )];
[self.navigationController.navigationBar addGestureRecognizer: self.revealViewController.panGestureRecognizer];
}

Swift

override func viewDidLoad() {
super.viewDidLoad()
//action for left Swipe
self.revealButtonItem.target = self.revealViewController
self.revealButtonItem.action = "revealToggle:"
    self.navigationController.navigationBar.addGestureRecognizer(self.revealViewController.panGestureRecognizer)
//action for Right Swipe
self.rightIcon.target = self.revealViewController
self.rightIcon.action = "rightRevealToggle:"
    self.navigationController.navigationBar.addGestureRecognizer(self.revealViewController.panGestureRecognizer)
}

I figured out what the problem was. In loadStoryboardControllers method [self performSegueWithIdentifier:SWSegueRightIdentifier sender:nil]; was commented out. If we implement right view controller this has to be uncommented.

You requested that I look at this thread.

I do not have experience with storyboards.

So, I am pasting below the code I have in my projects that allow for the Right Hand Side. Take a look at the section I commented. Hopefully, this will set you on the right path.

Good luck

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions
{
    UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window = window;

    FrontViewController *frontViewController = [[FrontViewController alloc] init];
    RearViewController *rearViewController = [[RearViewController alloc] init];

    UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
    UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController];

    SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavigationController     frontViewController:frontNavigationController];
    revealController.delegate = self;

// THIS SECTION RIGHT BELOW IS PROBABLY WHAT YOU WANT TO LOOK AT
    RightViewController *rightViewController = rightViewController =     [[RightViewController alloc] init];
    rightViewController.view.backgroundColor = [UIColor greenColor];

    revealController.rightViewController = rightViewController;

    revealController.bounceBackOnOverdraw=NO;
    revealController.stableDragOnOverdraw=YES;

    self.viewController = revealController;

    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

There is a try-catch condition between line on 435 to 444 on SWRevealViewController.m. Just rearrange the statement as following

        [self performSegueWithIdentifier:SWSegueRightIdentifier sender:nil];
        [self performSegueWithIdentifier:SWSegueFrontIdentifier sender:nil];
        [self performSegueWithIdentifier:SWSegueRearIdentifier sender:nil];

Now my right-menu/rightViewController is working even though i am not using the leftmenu/rearViewController.

you can also do what shad suggested. But if you are getting a flag with the right you can just replace

- (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
    {
        [self performSegueWithIdentifier:SWSegueRearIdentifier sender:nil];
    }
    @catch(NSException *exception) {}

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

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


}

with

 - (void)loadStoryboardControllers
{

//[self performSegueWithIdentifier:SWSegueRightIdentifier sender:nil];
[self performSegueWithIdentifier:SWSegueFrontIdentifier sender:nil];
[self performSegueWithIdentifier:SWSegueRearIdentifier sender:nil];

}

as you can see i commented out

//[self performSegueWithIdentifier:SWSegueRightIdentifier sender:nil];

becasue thats the one giving you an issue. If its the front or rear you can do the same

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!