This is a migrated thread and some comments may be shown as answers.

Side Drawer Push Navigation Controller

7 Answers 164 Views
SideDrawer
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Damien
Top achievements
Rank 1
Damien asked on 15 Sep 2015, 06:19 PM

Hi All,

 I have been trying to figure out how best to change the main content when using the side drawer but there are no examples and when I try using the Navigation Controller example posted in the forum it doesnt work.

 

Can someone share how to change the main content view controller when a menu item is clicked?

 

Thanks

Damien

7 Answers, 1 is accepted

Sort by
0
Yoanna
Telerik team
answered on 16 Sep 2015, 08:23 AM
Hello, Damien,

thank you for contacting us.

In -sideDrawer:didSelectItemAtIndexPath method of TKSideDrawerDelegate you will be able to push a new UIViewController when an item in TKSideDrawer is selected. This is how this could be done:

@interface ViewController () <TKSideDrawerDelegate>
 
@end
 
@implementation ViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
   
    TKSideDrawerView* sideDrawerView = [[TKSideDrawerView alloc] initWithFrame:self.view.frame];
    [self.view addSubview:sideDrawerView];
    TKSideDrawer* drawer = sideDrawerView.sideDrawer;
    drawer.delegate = self;
  
    drawer.style.headerHeight = 44;
 
    TKSideDrawerSection *section = [drawer addSectionWithTitle:@"Primary"];
    [section addItemWithTitle:@"Social"];
    [section addItemWithTitle:@"Promotions"];
     
    section = [drawer addSectionWithTitle:@"Labels"];
    [section addItemWithTitle:@"Important"];
    [section addItemWithTitle:@"Starred"];
    [section addItemWithTitle:@"Sent Mail"];
    [section addItemWithTitle:@"Drafts"];
     
    [drawer show];
}
 
 
-(void)sideDrawer:(TKSideDrawer *)sideDrawer didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    MyViewController* controller = [[MyViewController alloc] init];
   [self presentViewController:controller animated:YES completion:nil];
}
 
@end

I hope this answers your question. If you have further questions do not hesitate to contact us.

Regards,
Yoanna
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Damien
Top achievements
Rank 1
answered on 16 Sep 2015, 05:35 PM

Hi Yoanna,

 

Thanks for getting back to me.

I understand how to present a view controller when the menu is clicked but when using a navigation controller this does not work for me.

 

ie. [self.navigationController pushViewController:contactListVC animated:YES];

 Is there an example where a navigation controller is used with the side drawer to push a viewcontroller onto the navigation stack?

 I tried the suggestions here: http://www.telerik.com/forums/sidedrawer-goes-behind-uinavigationbar-when-using-uinavigationbarcontroller

 

but that does not push the controller for some reason.

 

Regards

Damien

0
Yoanna
Telerik team
answered on 18 Sep 2015, 04:08 PM
Hi, Damien, 

it seem like I misunderstood your question. Please, take my apology. 

In order to use navigation controller with TKSideDrawer you need to create a TKSideDrawerController with content of UINavigationController and set TKSideDrawerController as a root view controller. 
The following code snippet shows how it is done:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
     
    MYVC *main = [[MYVC alloc] init];
    UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:main];
 
    TKSideDrawerController *sideDrawerController = [[TKSideDrawerController alloc] initWithContent:navController];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window setRootViewController:sideDrawerController];
    [self.window makeKeyAndVisible];
     
    return YES;
}


Once this is set you have an instance of TKSideDrawer in your view controller. And you can start using the navigation controller as follows:
@interface MYVC () <TKSideDrawerDelegate>
 
@end
 
@implementation MYVC
 
-(void)viewDidLoad
{
    [super viewDidLoad];
 
    self.sideDrawer.delegate = self;
  
    UIBarButtonItem *showSideDrawerButton = [[UIBarButtonItem alloc] initWithTitle:@"Show" style:UIBarButtonItemStyleDone target:self action:@selector(showSideDrawer)];
    self.navigationItem.rightBarButtonItem = showSideDrawerButton;
     
    TKSideDrawerSection *sectionPrimary = [self.sideDrawer addSectionWithTitle:@"Primary"];
    [sectionPrimary addItemWithTitle:@"Social"];
    [sectionPrimary addItemWithTitle:@"Promotions"];
     
    TKSideDrawerSection *sectionLabels = [self.sideDrawer addSectionWithTitle:@"Labels"];
    [sectionLabels addItemWithTitle:@"Important"];
    [sectionLabels addItemWithTitle:@"Starred"];
}
 
- (void)showSideDrawer
{
    [self.sideDrawer show];
}
 
-(void)sideDrawer:(TKSideDrawer *)sideDrawer didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    ViewController* vc = [[ViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}
 
@end

I hope this helps. Should you have any questions I will be glad to help.

Regards,
Yoanna
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Damien
Top achievements
Rank 1
answered on 18 Sep 2015, 07:20 PM

Thanks Yoanna,

The issue was where you are getting the sideDrawer from.

Once I got this from the rootViewController it started working as expected.

I think it would be good to add this to your example

-(TKSideDrawer*)sideDrawer

{

     TKSideDrawerController * rootViewController = (TKSideDrawerController*)[[(AppDelegate*)[[UIApplication sharedApplication] delegate] window] rootViewController];

    return rootViewController.sideDrawer;

}

0
Yoanna
Telerik team
answered on 22 Sep 2015, 07:54 AM
Hello, Damien, 

I am glad that I helped. 
We will consider adding a help article that covers how to use navigation controller with TKSideDrawer, thank you for this suggestion. 

If you have any questions do not hesitate to contact us.

Regards,
Yoanna
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
chaitanya
Top achievements
Rank 1
answered on 28 Jan 2016, 02:28 AM

Thanks Yoanna.

 

Can you help me in getting this solution of selected item of telerik control in C# and fire the event?

 

Thanks in advance...

0
Adrian
Telerik team
answered on 28 Jan 2016, 11:38 AM
Hello, Chaitanya,

You can find my response in your other support thread.

Regards,
Adrian
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
SideDrawer
Asked by
Damien
Top achievements
Rank 1
Answers by
Yoanna
Telerik team
Damien
Top achievements
Rank 1
chaitanya
Top achievements
Rank 1
Adrian
Telerik team
Share this question
or