when we will navigate to another view controller. then using back button popviewcontroller property we can come to first view controller.
but what to do when we using MFSideMenu drawer. while clicking on drawer menu navigate to another screen. then how to come back on first view controller.
for navigating to another viewcontroller. I have used following code.
SCMainMenuViewController *scMainView = [[UIStoryboard storyboardWithName:#"Main" bundle:nil]instantiateViewControllerWithIdentifier:#"scMainMenuController"];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:scMainView];
[self.menuContainerViewController setCenterViewController:nav];
[self.menuContainerViewController setMenuState:MFSideMenuStateClosed completion:^{
}];
Try this:
HomeView *Home = [[HomeView alloc] initWithNibName:#"HomeView" bundle:nil];
NSArray *controllers = [NSArray arrayWithObject:Home];
self.navigationController.viewControllers = controllers;
Related
I am trying to present a UITableViewController modally on one of my view controllers which is further embedded in a UITabBarController. The code I am using is -
ContactTableViewController *contactsVC=[self.storyboard instantiateViewControllerWithIdentifier:#"contact"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:contactsVC];
navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
contactsVC.myDelegate = self;
[self.navigationController presentViewController:navController animated:YES completion:nil];
The view is presented just fine the first time I do it but when I navigate to this view again in my app, the view being presented is completely blank.. No navigation bar buttons, no title, nothing..
Can't figure out a reason... Any help is very much appreciated!
UPDATE:
HomeViewController *vc = [[HomeViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
This what I do to navigate to that view again while unhiding the tab bar. Home View is the view that presents the Contacts Table View modally.
I have a navigation controller which has view controller(VC1) . This view controller has 3 button out of which 1 directs to a tab bar controller. From tab1 of the tab bar controller a button is there which navigates to a View controller(vc2).
The problem is VC2 is not displaying the tab bar. How can I make my VC2 display the tab bar.
Navigation Controller—> View Controller-->Tab bar Controller —>Tab1 -> View Controller (does not show tab bar)
I am doing this in IOS
Using a tabbarcontroller within a navigation controller is not recommended by Apple. However it is possible to do so.
In the VC1, write the following code.
UITabBarController *tabBarController = [[UITabBarController alloc] init];
MyStartViewController *startController = [[MyStartViewController alloc] initWithNibName:#"MyStartViewController" bundle:Nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:startController];
SecondViewController *viewController2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
self.viewControllers = #[navController, viewController2];
[self.navigationController pushViewController:tabBarController animated:YES];
Now within startController, add a UIButton. And in the button action, push the new VC2 from it.
Button action:
- (IBAction)buttonPressed {
MyViewController2 *vc2 = [[MyViewController2 alloc] initWithNibName:#"MyViewController2" bundle:nil];
[self.navigationController pushViewController:vc2 animated:YES];
}
Hope this will serve your purpose.
I had an application in which I need to have a login or register system before the tab bar controller is added to the window, such as in Instagram.
I have added 5 navigation controllers (with view controller as its root) to the UITabBarController and then set it as the root of the window. Before that, I need to have another UINavigationController for the login system.
If I add that, how do I remove it before adding tab?
Another problem is that I also have to handle logging out, so I need to come back to it.
Can anybody help me with me how to do this?
I suggest to you loading Loginview From Delegate window as we did Normally. and from Logged Success its button click you set TabbarController like this:-
UIViewController *viewControllerPostalCode2 = [[cntrServices alloc] initWithNibName:#"cntrServices" bundle:nil];
UIViewController *viewControllerPostalCode3 = [[cntrInquiryViewController alloc] initWithNibName:#"cntrInquiryViewController" bundle:nil];
UINavigationController *navPostage1 = [[UINavigationController alloc] initWithRootViewController:viewControllerPostalCode2];
UINavigationController *navPostage2 = [[UINavigationController alloc] initWithRootViewController:viewControllerPostalCode3];
//
navPostage1.navigationBar.tintColor =DARK_BACKGROUNDNavigation;
navPostage2.navigationBar.tintColor =DARK_BACKGROUNDNavigation;
//
self.tabBarForServicesController = [[UITabBarController alloc] init];
self.tabBarForServicesController.delegate=self;
self.tabBarForServicesController.viewControllers = [NSArray arrayWithObjects:navPostage1,navPostage2,nil];
[self.navigationController pushViewController:self.tabBarForServicesController animated:YES];
I Done this type of Task using this method and at the Logged Out just poptoRootviewController work back to the Logged in Screen.
I have done this like adding my tabbarcontroller as rootViewController to UIWindow and in applicationbecomeactive delegate i present a controller with navigation controller like when required and simply dismiss the controller when authentication done
UIViewController *topViewController = [self.navController topViewController];
if (![topViewController isKindOfClass:[LGLoginViewController class]]) {
[self.navController popToRootViewControllerAnimated:YES];
self.navController = nil;
LGLoginViewController* loginView = [[LGLoginViewController alloc] initWithNibName:#"LGLoginViewController"bundle:nil];
if (!self.navController) {
self.navController = [[UINavigationController alloc] initWithRootViewController:loginView];
} else {
[self.navController initWithRootViewController:loginView];
}
self.navController.delegate = self;
[self.window.rootViewController presentModalViewController:self.navController animated:NO];
}
I am developing a ViewController (login app) with a single button, when I press this button I want to appear my UISplitView like this:
- (IBAction)loadSplitViewController:(id)sender {
[self showSplitViewController];
}
and the code developed for the creation of my splitViewController is this:
-(void)showSplitViewController{
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPad" bundle: nil];
LeftViewController *leftViewController = [mainStoryboard instantiateViewControllerWithIdentifier:#"LeftViewController"];
RightViewController *rightViewController = [mainStoryboard instantiateViewControllerWithIdentifier:#"RightViewController"];
UINavigationController *leftNavController = [[UINavigationController alloc] initWithRootViewController:leftViewController];
UINavigationController *rightNavController = [[UINavigationController alloc] initWithRootViewController:rightViewController];
UISplitViewController *splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = [NSArray arrayWithObjects:leftNavController, rightNavController, nil];
leftViewController.delegate = rightViewController;
splitViewController.delegate = rightViewController;
[self presentViewController:splitViewController animated:YES completion:^{}];
}
the thing is... if I use for display my splitViewController this line:
[self presentViewController:splitViewController animated:YES completion:^{}];
throws me an error
I also tried with
[self.view addSubview:splitViewController.view];
but this way my splitViewController never rotates, and delegates doesn't work as well... and I don't want my splitViewController to be a subview of my viewController, I want it to appear more like an independient modalView
any help I'll appreciate
thanks in advance
Split view controllers really should be the root view controller of the window (in fact Apple says it has to be, though there seem to be some examples where this isn't true). Instead of presenting it, you could just switch the window's root view controller to be the split view controller.
self.view.window.rootViewController = splitViewController;
Can I change the first screen of a tab item programatically?
For example,
When user is in Tab A, upon tapping a button there, user will be
navigated to Tab C with Screen 1 However, when user is in Tab C, upon
tapping a button here, user will be navigated to Tab C with Screen 2.
Therefore, both screen 1 and 2 will be the first screen of Tab C
depend on where the user comes from.
Can I achieve something like that?
Thanks!
Based on this post How to replace a navigation root controller by tab bar controller in existing iphone app , can change the view controllers by this code:
NSMutableArray * viewControllers = [[NSMutableArray alloc]init];
FirstViewController * firstViewController = [[FirstViewController alloc]initWithNibName:#"FirstViewController" bundle:nil];
UINavigationController * nvc = [[UINavigationController alloc] initWithRootViewController:firstViewController];
[firstViewController release];
[viewControllers addObject:nvc];
[nvc release];
SecondViewController * secondViewController = [[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
nvc = [[UINavigationController alloc] initWithRootViewController:secondViewController];
[secondViewController release];
[viewControllers addObject:nvc];
[nvc release];
UITabBarController * tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = viewControllers;
[window addSubview:tabBarController.view];