Side Drawer Push Navigation Controller

8 posts, 0 answers
  1. Damien
    Damien avatar
    5 posts
    Member since:
    Sep 2015

    Posted 15 Sep 2015 Link to this post

    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

  2. Yoanna
    Admin
    Yoanna avatar
    44 posts

    Posted 16 Sep 2015 Link to this post

    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
  3. DevCraft banner
  4. Damien
    Damien avatar
    5 posts
    Member since:
    Sep 2015

    Posted 16 Sep 2015 in reply to Yoanna Link to this post

    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

  5. Yoanna
    Admin
    Yoanna avatar
    44 posts

    Posted 18 Sep 2015 Link to this post

    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
  6. Damien
    Damien avatar
    5 posts
    Member since:
    Sep 2015

    Posted 18 Sep 2015 in reply to Yoanna Link to this post

    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;

    }

  7. Yoanna
    Admin
    Yoanna avatar
    44 posts

    Posted 22 Sep 2015 Link to this post

    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
  8. chaitanya
    chaitanya avatar
    1 posts
    Member since:
    Jan 2016

    Posted 27 Jan in reply to Yoanna Link to this post

    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...

  9. Adrian
    Admin
    Adrian avatar
    167 posts

    Posted 28 Jan Link to this post

    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
Back to Top
DevCraft banner