SebastienMichoy/MSSlidingPanelController

Storyboard usage

Closed this issue · 6 comments

Using storyboard example, which code I have to write if I want open and close the slider tapping a button instead using gestures?

Hi !

You need to create a new class which corresponds to the center view controller and to connect the StoryBoard's button to your leftButtonTouched: method.

#import <UIKit/UIKit.h>

@interface CenterViewController : UITableViewController

- (IBAction)leftButtonTouched:(id)sender;

@end
#import "CenterViewController.h"
#import "MSViewControllerSlidingPanel.h"

@implementation CenterViewController

- (IBAction)leftButtonTouched:(id)sender
{
    NSLog(@"Test");

    if ([[self slidingPanelController] sideDisplayed] == MSSPSideDisplayedLeft)
        [[self slidingPanelController] closePanel];
    else
        [[self slidingPanelController] openLeftPanel];
}

@end

Let me know if you have any issues.

perfect!
it works fine!
thanks a lot
But I have another two question:

On the example without storyboard when you open the slider panel the status bar is changing colour (from blue to black).
How can I do this using storyboard example?

the last question (I promise it :) ) is:
how can I change something (for example a uilabel text) in center view when I press something in "left" view?

For both of your questions, you need to use code.

To change the status bar color, you have to use leftPanelStatusBarColor or/and rightPanelStatusBarColor properties. In addition, you can also use leftPanelStatusBarDisplayedSmoothly and rightPanelStatusBarDisplayedSmoothly to change the color smoothly or not.

By using #import "MSViewControllerSlidingPanel.h", you can access to your sliding panel controller.
So, you can access easily to your controllers by [[self slidingPanelController] leftPanelController], [[self slidingPanelController] rightPanelController] and [[self slidingPanelController] centerViewController].

I don't understood how I can use this:
"[[self slidingPanelController] centerViewController]"
to call an action in the panel.

Example:
I have one button on the left panel.
When I press it, then I want execute one method of centerViewController.
How can I do this using [[self slidingPanelController] centerViewController] into left panelviewController?

I guess the best way is to call a method of your left panel which will check if it can call the method of the center view.

Here is the code of the left panel:

#import <UIKit/UIKit.h>

@interface LeftViewController : UIViewController

- (IBAction)buttonTouched:(id)sender;

@end
#import "CenterViewController.h"
#import "LeftViewController.h"
#import "MSViewControllerSlidingPanel.h"

@implementation LeftViewController

- (IBAction)buttonTouched:(id)sender
{
    if ([[[self slidingPanelController] centerViewController] isKindOfClass:[CenterViewController class]])
        [[(CenterViewController *)[[self slidingPanelController] centerViewController] label] setText:@"Left button touched"];
}

@end

And here is the center view controller:

#import <UIKit/UIKit.h>

@interface CenterViewController : UIViewController

@property (nonatomic, strong)   IBOutlet UILabel    *label;

@end
#import "CenterViewController.h"

@implementation CenterViewController

@end

Now you just have to connect the buttonTouched: method and the label property with the StoryBoard.

Does it seem more clear?

wonderful!!!
you are a pro. seriously
thanks a lot