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
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
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
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
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;
}
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
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...
You can find my response in your other support thread.
Regards,
Adrian
Telerik