SWRevealViewController - RightViewController

时间:2014-07-01 18:35:29

标签: ios objective-c iphone swift swrevealviewcontroller

我使用SWRevealViewController在我的应用中实现了两个侧面导航视图。我按照故事板方法成功实现了后视图和前视图。我尝试通过故事板设置与后视图完全相同的正确视图,但是无法做到。

我已将显示视图控制器segue设置为" sw_right"但看起来- (void)prepareForSegue:(SWRevealViewControllerSegue *)segue sender:(id)sender没有被- (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]; }; } } } 识别出来,因为" sw_rear"和" sw_front"

我错过了什么? enter image description here

{{1}}

5 个答案:

答案 0 :(得分:9)

enter image description here

这是示例项目,这个工作正常,我为自己制定了,下载链接是

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

下载项目后你要删除项目,请使用此链接

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

这里你需要在前视图控制器上右键滑动,在特定视图中添加UIBarButtonItem控制器

    @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

并添加一些函数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];
}

<强>夫特

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

答案 1 :(得分:5)

我弄清楚问题是什么。 loadStoryboardControllers方法[self performSegueWithIdentifier:SWSegueRightIdentifier sender:nil];已被注释掉。如果我们实现了右视图控制器,则必须取消注释。

答案 2 :(得分:1)

你要求我查看这个帖子。

我没有使用故事板的经验。

所以,我粘贴在我允许右手边的项目中的代码之下。 看看我评论的部分。希望这会让你走上正确的道路。

祝你好运

- (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;
}

答案 3 :(得分:1)

在SWRevealViewController.m上的435到444行之间有一个try-catch条件。只需将声明重新排列为以下

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

现在我的右菜单/ rightViewController正在工作,即使我没有使用leftmenu / rearViewController。

答案 4 :(得分:0)

你也可以做shad建议的。但如果您正在获得右侧的旗帜,则可以直接替换

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


}

 - (void)loadStoryboardControllers
{

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

}

你可以看到我注释掉了

//[self performSegueWithIdentifier:SWSegueRightIdentifier sender:nil];
因为这是给你一个问题的人。如果它的前面或后面你可以做同样的