SWRevealViewController - RightViewController

I use SWRevealViewController to implement two side navigation views in my application. I followed the method of history and successfully implemented the rear view and front view. I tried to set the correct view in the same way as the rear view through the storyboard, but could not do it.

I set the sevue view view to sw_right, but it doesn't seem to be recognized - (void)prepareForSegue:(SWRevealViewControllerSegue *)segue sender:(id)sender , which is called twice for "sw_rear" and "sw_front"

What am I missing? enter image description here

 - (void)prepareForSegue:(SWRevealViewControllerSegue *)segue sender:(id)sender { // $ using a custom segue we can get access to the storyboard-loaded rear/front view controllers // the trick is to define segues of type SWRevealViewControllerSegue on the storyboard // connecting the SWRevealViewController to the desired front/rear controllers, // and setting the identifiers to "sw_rear" and "sw_front" // $ these segues are invoked manually in the loadView method if a storyboard // was used to instantiate the SWRevealViewController // $ none of this would be necessary if Apple exposed "relationship" segues for container view controllers. NSString *identifier = segue.identifier; if ( [segue isKindOfClass:[SWRevealViewControllerSegue class]] && sender == nil ) { if ( [identifier isEqualToString:SWSegueRearIdentifier] ) { segue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc) { [self _setRearViewController:dvc animated:NO]; }; } else if ( [identifier isEqualToString:SWSegueFrontIdentifier] ) { segue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc) { [self _setFrontViewController:dvc animated:NO]; }; } //This is never executed even after setting the identifier else if ( [identifier isEqualToString:SWSegueRightIdentifier] ) { segue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc) { [self _setRightViewController:dvc animated:NO]; }; } } } 
+4
ios objective-c iphone swift swrevealviewcontroller
source share
5 answers

I realized what the problem is. The method [self performSegueWithIdentifier:SWSegueRightIdentifier sender:nil]; was noted in [self performSegueWithIdentifier:SWSegueRightIdentifier sender:nil]; . If we implement a right-view controller, this should be uncommented.

+5
source share

enter image description here

Here is an example project, it works fine, I developed a download link for myself

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

after loading the project and want to delete the project, use this link

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

here you need to scroll properly on the appearance controller, add the UIBarButtonItem to the specific 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 some features: 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) } 
+9
source share

You asked to see this stream.

I have no experience with the storyboard.

So, I am inserting below the code that I have in my projects that allow the Right Hand Side. Take a look at the section that I commented on. Hope this leads you to 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; } 
+1
source share

In SWRevealViewController.m there is a try-catch condition between line 435-444. Just change the statement as follows

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

Now my right menu / rightViewController works, although I do not use leftmenu / rearViewController.

+1
source share

You can also do what shad suggested. But if you get the flag on the right, you can simply 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) {} } } 

from

  - (void)loadStoryboardControllers { //[self performSegueWithIdentifier:SWSegueRightIdentifier sender:nil]; [self performSegueWithIdentifier:SWSegueFrontIdentifier sender:nil]; [self performSegueWithIdentifier:SWSegueRearIdentifier sender:nil]; } 

as you can see i commented

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

Because it gives you a problem. If its front or back you can do the same

0
source share

All Articles