stefanoa / SASlideMenu

Library to create iOS sliding menu compatible with storyboards
568 stars 118 forks source link

Can I show another ViewController from different story board? #128

Closed rish7 closed 10 years ago

rish7 commented 10 years ago

Hi,

Can you please help me, is there anyway I can show view controller from different storyboard when user pressed on menu item?

Thank you, Naga Harish.

stefanoa commented 10 years ago

Hi Naga, your SASlideMenuViewController needs to implement:

-(void) tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath;

The implementation needs to load a segue from the desired storyboard.

rish7 commented 10 years ago

I tried but, It is how showing left menu in that screen. Can you please give me the code sample.

Thank you, Naga Harish.

stefanoa commented 10 years ago

If you send me a sample project I will have a look at it.

Stefano

rish7 commented 10 years ago

Please find the sample here. In slidemenu if you click on any row will show you the second screen where we did not find(try to click on that area) any menu left icon.

Download link for source code http://1drv.ms/1osiNyb

Thank you, Naga Harish.

stefanoa commented 10 years ago

Hi Naga,

the problem with your code is that in order to present a content ViewController you have to use the segue. It is not enough to add a controller on top of the navigation controller. I have changed a little your code and now it seems that is loading the controller from the other storyboard.

//
//  ExampleiPadViewController.m
//  SASlideMenuiPad
//
//  Created by Stefano Antonelli on 3/13/13.
//  Copyright (c) 2013 Stefano Antonelli. All rights reserved.
//

#import "ExampleiPadViewController.h"
#import "SASlideMenuRootViewController.h"

@interface ExampleiPadViewController ()
@property (nonatomic) CGFloat selectedHue;
@property (nonatomic) CGFloat selectedBrightness;

@end

@implementation ExampleiPadViewController

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return YES;
}
-(id) initWithCoder:(NSCoder *)aDecoder{
    if (self = [super initWithCoder:aDecoder]) {
        self.selectedHue = 0.0;
        self.selectedBrightness = 1.0;
    }
    return self;
}

#pragma mark -
#pragma mark SASlideMenuDataSource

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([segue.identifier isEqualToString:@"testScreen"]) {
        UINavigationController* destinationController = (UINavigationController*) segue.destinationViewController;
        UIStoryboard *secondStoryBoard = [UIStoryboard storyboardWithName:@"TestScreen" bundle:nil];
        UIViewController *theScreen = [secondStoryBoard instantiateInitialViewController];
        destinationController.viewControllers = [NSArray arrayWithObjects:theScreen, nil];
    }
}

-(void) configureMenuButton:(UIButton *)menuButton{
    menuButton.frame = CGRectMake(0, 0, 40, 29);
    [menuButton setImage:[UIImage imageNamed:@"menuicon"] forState:UIControlStateNormal];
}

-(NSIndexPath*) selectedIndexPath{
    return [NSIndexPath indexPathForRow:0 inSection:0];
}

/*
 Maps menu rows to segueId.
 */
-(NSString*) segueIdForIndexPath:(NSIndexPath *)indexPath{

    switch (indexPath.row) {
        case 0:
            return @"colored";
            break;
        default:
            return @"testScreen";
            break;
    }

}

#pragma mark -
#pragma mark UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"Row %d",indexPath.row];
    return cell;
}

-(CGFloat) leftMenuVisibleWidth{
    return 280;
}

#pragma mark -
#pragma mark SASlideMenuDelegate

-(void) slideMenuWillSlideIn:(UINavigationController *)selectedContent{
    NSLog(@"slideMenuWillSlideIn");
}
-(void) slideMenuDidSlideIn:(UINavigationController *)selectedContent{
    NSLog(@"slideMenuDidSlideIn");
}
-(void) slideMenuWillSlideToSide:(UINavigationController *)selectedContent{
    NSLog(@"slideMenuWillSlideToSide");
}
-(void) slideMenuDidSlideToSide:(UINavigationController *)selectedContent{
    NSLog(@"slideMenuDidSlideToSide");
}
-(void) slideMenuWillSlideOut:(UINavigationController *)selectedContent{
    NSLog(@"slideMenuWillSlideOut");
}
-(void) slideMenuDidSlideOut:(UINavigationController *)selectedContent{
    NSLog(@"slideMenuDidSlideOut");
}
-(void) slideMenuWillSlideToLeft:(UINavigationController *)selectedContent{
    NSLog(@"slideMenuWillSlideToLeft");
}
-(void) slideMenuDidSlideToLeft:(UINavigationController *)selectedContent{
    NSLog(@"slideMenuDidSlideToLeft");
}

@end
rish7 commented 10 years ago

Hi Stefano,

Thank you very much. I wrote little code to show left menu for two storyboard viewcontroller. But the way you told is working fine with out any single line of code.

Thank you, Naga Harish.