Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
294 views
in Technique[技术] by (71.8m points)

ios - SWRevealViewController - RightViewController

I'm using SWRevealViewController for implementing two side navigation views in my application. I followed the story board method and successfully implemented the rear view and front view. I tried setting right view exactly like the rear view via storyboard, but couldn't do it.

I have set the reveal view controller segue to "sw_right" but it looks like it is not being recognized by - (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];
        };
    }
  }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

enter image description here

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)
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...