I am using ECsliding controller for slide menu.swipe gestrure working good in my case but when click button nothing happened.
My case is:
After two screen, I wanted to show slide menu so i have set ECSlide like belowe in my second screen and so far everything ok.
In third view controller I set a button to show menu.Button get clicked but menu not open.
- (void)viewWillAppear:(BOOL)animated{
if (![self.slidingViewController.underLeftViewController isKindOfClass:[LeftViewController class]]) {
self.slidingViewController.underLeftViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"LeftViewController"];
}
[self.navigationController setNavigationBarHidden:YES animated:YES];
if ([self.checkStr isEqualToString:#"1"])
{
//provider
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main"
bundle: nil];
LeftViewController *leftMenu = (LeftViewController*)[mainStoryboard
instantiateViewControllerWithIdentifier: #"LeftViewController"];
// Create your menu view controller
ProfileController *leftMenuONE = (ProfileController*)[mainStoryboard
instantiateViewControllerWithIdentifier: #"ProfileControllerID"];
// configure top view controller
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:leftMenuONE];
self.slidingViewController = [ECSlidingViewController slidingWithTopViewController:navigationController];
self.slidingViewController.underLeftViewController = leftMenu;
// enable swiping on the top view
[navigationController.view addGestureRecognizer:self.slidingViewController.panGesture];
// configure anchored layout
self.slidingViewController.anchorLeftRevealAmount = 250.0;
[self.navigationController pushViewController:self.slidingViewController animated:YES];
}
else
{
//user
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main"
bundle: nil];
LeftViewController *leftMenu = (LeftViewController*)[mainStoryboard
instantiateViewControllerWithIdentifier: #"LeftViewController"];
// Create your menu view controller
UserProfileController *leftMenuONE = (UserProfileController*)[mainStoryboard
instantiateViewControllerWithIdentifier: #"UserProfileControllerID"];
// configure top view controller
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:leftMenuONE];
self.slidingViewController = [ECSlidingViewController slidingWithTopViewController:navigationController];
self.slidingViewController.underLeftViewController = leftMenu;
// enable swiping on the top view
[navigationController.view addGestureRecognizer:self.slidingViewController.panGesture];
// configure anchored layout
self.slidingViewController.anchorLeftRevealAmount = 250.0;
[self.navigationController pushViewController:self.slidingViewController animated:YES];
}
}
LeftViewController is my menu view controller.
Third view controller will load based condition.example if string is one,it will go to one view controller otherwise anther view controller.
Thirdview.h
- (IBAction)menuAction:(id)sender
{
[self.slidingViewController anchorTopViewToRightAnimated:YES];
}
-(void)viewWillAppear:(BOOL)animated
{
if (![self.slidingViewController.underLeftViewController isKindOfClass:[LeftViewController class]]) {
self.slidingViewController.underLeftViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"LeftViewController"];
}
}
Related
I have three UIViewControllers. I am navigating to VC3 from VC1. I want to navigate to VC2 if I click on cancel or done button from VC3.
I have added the VC2 controller to navigation stack programmatically.
DocListViewController *temp1 = [[DocListViewController alloc] initWithNibName:#"DocListViewController" bundle:nil];
[self.navigationController addChildViewController: temp1];
for (UIViewController *controllers in self.navigationController.viewControllers) {
if([controllers isKindOfClass: [DocListViewController class]]) {
DocListViewController *VC2ViewController = (DocListViewController*)controllers;
[self.navigationController popToViewController:VC2ViewController animated:YES];
}
}
What you are doing wrong here is adding it as child view controller,addChildViewController as it as a child of the current view controller does not add it in the navigation stack.
You need to insert the controller in you navigation stack before doing popToViewcontroller.
VC2 *temp1 = [[VC2 alloc] initWithNibName:#"DocListViewController" bundle:nil];
NSMutableArray *vcArray = [NSMutableArray arrayWithArray:self.navigationController.viewControllers] ;
[vcArray insertObject:temp1 atIndex:1]; // ** This index is `1` assuming you only have 2 controllers and we are pushing it in the middle,
// if you have many vc in navigation stack and just want to insert a new vc just before your current vc go with this:
/*
[vcArray insertObject:temp1 atIndex:vcArray.count - 2];
*/
self.navigationController.viewControllers = vcArray;
/* --- ** This part is also not needed:
for (UIViewController *controllers in self.navigationController.viewControllers) {
if([controllers isKindOfClass: [DocListViewController class]]) {
[self.navigationController popToViewController: controllers animated:YES];
}
}
*/
[self.navigationController popViewControllerAnimated:true];
Also: you don't need VC2 *VC2ViewController = (VC2*)controllers;
inside the if block as you only need a UIViewController type object for pop-ing.
I have just edited your code, get the project reference below
Edit:
Adding GitHub link for better reference:
PlayingWithNavigation
You can navigate to VC2 using pushviewContoller
NSString * storyboardName = #"Main";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
VC2 * VC2View = [storyboard instantiateViewControllerWithIdentifier:#"VC2ID"]; // "VC2ID" is the storyboard Id of your view controller
[self.navigationController pushViewController:VC2View animated:YES];
UIViewController *vc2 = [[UIViewController alloc] init];
UIViewController *vc3 = [[UIViewController alloc] init];
[self.navigationController pushViewController:vc2 animated:NO];
[self.navigationController pushViewController:vc3 animated:YES];
Try this.
I have a button action in which i'm trying to open view controller on condition bases, but the view controller are not opening. I have use story board identifier method to open the new view controller, i'm confused why it isn't opening. My condition is not working fine, i got null but when i got login and comes back to home screen again it again shows null.
My code is,
- (IBAction)History:(id)sender {
NSString *savedValue = [[NSUserDefaults standardUserDefaults]
stringForKey:#"pin"];
if ([savedValue length]==0) {
NSLog(#"INNNNN");
UIStoryboard *story=[UIStoryboard storyboardWithName:#"Main" bundle:nil];
RegisterViewController *vc = [story instantiateViewControllerWithIdentifier: #"Register"];
[self.navigationController pushViewController:vc animated:YES];
}else{
UIStoryboard *story=[UIStoryboard storyboardWithName:#"Main" bundle:nil];
DetailsViewController *vc = [story instantiateViewControllerWithIdentifier: #"detail"];
[self.navigationController pushViewController:vc animated:YES];
}
}
The story board looks like this,
if your All viewcontrollers does not embed in UINavigationcontroller (Root) then use presentViewController for navigation.
- (IBAction)History:(id)sender {
NSString *savedValue = [[NSUserDefaults standardUserDefaults]
stringForKey:#"pin"];
UIStoryboard *story=[UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *topViewVC;
if ([savedValue length]==0) {
RegisterViewController *vc = [story instantiateViewControllerWithIdentifier: #"Register"];
topViewVC = vc;
}else{
DetailsViewController *vc = [story instantiateViewControllerWithIdentifier: #"detail"];
topViewVC = vc;
}
[self presentViewController:topViewVC animated:true completion:nil];
}
option 2
if you want the pushViewController may be future purpose then dont do any changes in your code , just add UINavigationcontroller as root. Select your initial VC in storyboard then xcode menu --> Editor - -> Embed In --> Navigation Controller
It seems like you missed to embed your base view controller to navigation controller. Select your initial VC in storyboard. Go to Editor -> Embed In -> Navigation Controller.
I use swrevealviewcontroller to add slide menu to my app ,
Let consider we have menu like this one in pic
I need navigate from My appDelegate to any item in menu (ex:Map View Controller )
my tries :
in my appDelegate.m
UIStoryboard *storyboard =[UIStoryboard storyboardWithName:#"Main" bundle:nil];
InforView *school_view = [storyboard instantiateViewControllerWithIdentifier:#"info_view"];
[self.window makeKeyAndVisible];
[self.window.rootViewController presentViewController:school_view animated:YES completion:NULL];
When its move to InforView Controller it crash in viewdidload
- (void)viewDidLoad
{
[super viewDidLoad];
_nav_bar.target = self.revealViewController;
_nav_bar.action = #selector(revealToggle:);
// its crash here
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
my storyboard
navigation controller --> home view --> reveal View controller
reveal View controller has two views --> slide menu
navigation controller -- > Front view
my slide menu has some items as appear in pic
I need navigate from my appDelegate to one of this items
Finally I find the answer
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
// this any item in list you want navigate to
Home_tableView *home = (Home_tableView *) [storyboard instantiateViewControllerWithIdentifier:#"home_view"];
SlideMenu *slidemenu = (SlideMenu *)[storyboard instantiateViewControllerWithIdentifier:#"Menu_view"];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:home];
UINavigationController *smVC = [[UINavigationController alloc]initWithRootViewController:slidemenu];
// define rear and frontviewcontroller
SWRevealViewController *revealController = [[SWRevealViewController alloc]initWithRearViewController:smVC frontViewController:nav];
// make it as root
self.window.rootViewController = revealController;
In the SidebarDemo project, you can use the following code to show MapViewController on initial loading.
SWRevealViewController *revealViewController = (SWRevealViewController*)self.window.rootViewController;
UIStoryboard *storyboard =[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
MapViewController *mapVC = [storyboard instantiateViewControllerWithIdentifier:#"MapID"];
[self.window makeKeyAndVisible];
UINavigationController* navController = (UINavigationController*)revealViewController.frontViewController;
[navController setViewControllers: #[mapVC] animated: NO ];
[revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
After makeKeyAndVisible, the frontViewController and realViewController of the revealViewController are loaded. And you can set rootViewController of frontViewController, which is a navigationController.
i needed to change the tab bar position to the top on my view controller and i found out how to do it. The problem is that now in one of the tabs i need to push a new view controller but when i do , the navigation bar doesn't show up. I tried embedding the new view controller in another navigation controller and it worked (showed the navigation bar) but it didn't showed the back button item. is there a way to do this?
Here some screen shots:
this is how i am navigating between tabs
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
switch (item.tag) {
case 1:
if (Home == nil) {
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Main"
bundle:nil];
Home = [sb instantiateViewControllerWithIdentifier:#"Home"];
}
[self.view insertSubview:Home.view belowSubview:mainTabBar];
break;
case 2:
if (Activity == nil) {
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Main"
bundle:nil];
Activity = [sb instantiateViewControllerWithIdentifier:#"Activity"];
}
[self.view insertSubview:Activity.view belowSubview:mainTabBar];
break;
case 3:
if (Discover == nil) {
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Main"
bundle:nil];
Discover = [sb instantiateViewControllerWithIdentifier:#"Discover"];
}
[self.view insertSubview:Discover.view belowSubview:mainTabBar];
break;
case 4:
if (Profile == nil) {
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Main"
bundle:nil];
Profile = [sb instantiateViewControllerWithIdentifier:#"Profile"];
}
[self.view insertSubview:Profile.view belowSubview:mainTabBar];
break;
default:
break;
}
this is the view controller i need to push.
Rather that instantiate your controllers when selecting them, you should instantiate and add them to an array then do this in the AppDelegate when you set up the window:
self.tabBarController.viewControllers = localViewControllersArray;
Just in case anyone needs this, the way i solved it was making all the tab view controllers childs of the main view controller so it managed the navigation by itself.
[self addChildViewController:self.Home];
I am having difficulty using IIViewDeck in my app. I am using storyboard. I have managed to bring leftviewcontroller which is a tableviewcontroller with cells that are supposed to segue to particular viewcontroller in the storyboard. How do I do this? I have put this in appdelegate.
UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
UIViewController *menuController = [mainStoryboard instantiateViewControllerWithIdentifier:#"mainSideNavMenu"];
UINavigationController* navigationController = (UINavigationController *) self.window.rootViewController;
self->viewDeckController = [[IIViewDeckController alloc] initWithCenterViewController:navigationController leftViewController:menuController rightViewController:nil];
self.window.rootViewController = self->viewDeckController;
You can manage it with code, with the didSelectRowAtIndexPath method of your table view.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
if (indexPath.row == 0) {
MyTripsViewController* newController = [sb instantiateViewControllerWithIdentifier:#"ViewController1"];
[self.viewDeckController closeLeftViewBouncing:^(IIViewDeckController *controller) {
self.viewDeckController.centerController = newController;
}];
}
if (indexPath.row == 1) {
MyTripsViewController* newController = [sb instantiateViewControllerWithIdentifier:#"ViewController2"];
[self.viewDeckController closeLeftViewBouncing:^(IIViewDeckController *controller) {
self.viewDeckController.centerController = newController;
}];
}
else {
MyTripsViewController* newController = [sb instantiateViewControllerWithIdentifier:#"ViewController3"];
[self.viewDeckController closeLeftViewBouncing:^(IIViewDeckController *controller) {
self.viewDeckController.centerController = newController;
}];
}
}
So you have to defined you row / viewController couple.
I know it's a bit late, but someone might find the answer useful at some point.
Max's answer is generally a good answer. However, the original poster's question is a bit vague. He/She didn't specify if the transition is required in the center view controller or the left one.
Assuming the transition is in the left view controller:
If you want push transition, you can use a code like:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
UINavigationController * nc = (UINavigationController *)self.viewDeckController.leftController;
UIViewController * vc = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"yourView"]; // use the name of the view (not the navigation view controller)
[nc pushViewController:vc animated:YES];
}
}
If you want Modal transition, just replace the code within the previous if statement clause with the following code:
UIViewController * vc = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"yourViewName"]; // don't use the name of a navigation controller
UINavigationController * nc = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentViewController:nc animated:YES completion:nil];
The navigation controller in this code is used to get the navigation bar shown. If you don't need the navigation bar, just omit the navigation controller definition and pass the view controller as a parameter instead in the presentViewController: animated: completion: method.
Assuming the transition is in the center view controller:
You can use the code Max had provided. Keep in mind that the way he showed the new view controller is by replacing the existing center view controller. The new view controller is neither pushed nor modally showed. If you want to push new view controller to the existing center view controller, you should use the same way I introduced the transition in the previous two pieces of code above. So, it should look like this:
Push Transition: (the following code should replace the code within the if statement clause in the first piece of code)
[self.viewDeckController closeLeftView];
UINavigationController * nc = (UINavigationController *)self.viewDeckController.centerController;
[nc pushViewController:[[[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"yourViewName"] parentViewController] animated:YES];
Modal Presentation: (the following code should replace the code within the if statement clause in the first piece of code)
[self.viewDeckController closeLeftView];
UINavigationController * center = (UINavigationController *)self.viewDeckController.centerController;
UIViewController * vc = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"yourViewName"];
UINavigationController * nc = [[UINavigationController alloc] initWithRootViewController:vc];
[center presentViewController:nc animated:YES completion:nil];