Set Root View In App delegate with View Hierachy - objective-c

I want to be able to manually set the root view controller in app delegate intact with it's view hierarchy
My View Controller Hierarchy is
TabBarController
UINavigationController
FirstViewController
DetailedViewController (I want to show this view)
Currently what I do is
DetailedViewController *vc = (DetailedViewController *)[mainStoryBoard instantiateViewControllerWithIdentifier:#"DetailedViewController"];
[self.window setRootViewController:vc];
[vc performSelector:#selector(setup:) withObject:section];
which obviously ignores the hierarchy and therefore when the app loads, I dont have the nav bar nor the tab bar.
So I tried this
UITabBarController *tabBarController = [mainStoryBoard instantiateViewControllerWithIdentifier:#"tabController"];
tabBarController.selectedIndex = 0;
DetailedViewController *vc = (DetailedViewController *)[mainStoryBoard instantiateViewControllerWithIdentifier:#"DetailedViewController"];
UINavigationController *navController = [mainStoryBoard instantiateViewControllerWithIdentifier:#"NavController"];
[navController pushViewController:vc animated:YES];
[self.window setRootViewController:tabBarController];
But using this code I can view FirstViewController and not the DetailedViewController

Your view hirarchy is such that
You have tabbar that has navcontroller with a rootview of firstviewcontroller so this code add firstview as rootView
UITabBarController *tabBarController = [mainStoryBoard instantiateViewControllerWithIdentifier:#"tabController"];
tabBarController.selectedIndex = 0;
FrstViewController *firstView = (FirstViewController*)[mainStoryboard instantiateViewControllerWithIdentifier:#"FirstViewController"];
UINavigationController *navController = [UINavigationViewController alloc] initWithRootViewController:firstview]
self.tabbarController.viewControllers = [NSArray arrayWithObjects:navController,nil]
[self.window setRootViewController:tabBarController];
When the first we loads in viewDidload of it push detailviewcontroller
-(void) viewDidLoad
{
DetailedViewController *vc = (DetailedViewController *)[mainStoryBoard instantiateViewControllerWithIdentifier:#"DetailedViewController"];
[self.navigationController pushViewController vc];
}

Related

Loginviewcontroller before SWRevealviewcontroller with Storyboard objective C

I am using SWRevealViewcontroller by using this sample:
I want to add loginviewcontroller before SWRevealViewcontroller.
What I've tried:
Added loginviewcontroller in Storyboard. Set it as InitialViewcontroller.
Inside button action.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
MapViewController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:#"MapViewController"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[navController setViewControllers: #[rootViewController] animated: YES];
[self.revealViewController setFrontViewController:navController];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
But it is not working. Please help
viewController1
viewController2 *viewController2=[self.storyboard instantiateViewControllerWithIdentifier:#"viewController2Id"];
[self.navigationController pushViewController: viewController2 animated:YES];
viewController2
-(void)pushAfterLoginScreen
{
SidebarViewController *sidebarmemu =(SidebarViewController*) [self.storyboard instantiateViewControllerWithIdentifier:#"SidebarController"];
viewController3* viewController3 = (viewController2*)[self.storyboard instantiateViewControllerWithIdentifier:#"viewController2Id"];
SWRevealViewController *revealController;
UINavigationController *frontNavigationController;
UINavigationController *rearNavigationController;
frontNavigationController =[[UINavigationController alloc]initWithRootViewController: viewController2];
rearNavigationController =[[UINavigationController alloc]initWithRootViewController:sidebarmemu];
revealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
revealController.delegate = self;
self.swcontroller =revealController;
AppDelegate *app =(AppDelegate *)[[UIApplication sharedApplication]delegate];
app.window.rootViewController =self.swcontroller;
}
SWRevealViewcontroller which is already embed with the navigationController you need to pass control to SWRevealViewcontroller after successful login using presentViewController method by setting up the storyboard id to navigationController of SWRevealViewcontroller and navigate your app using below code:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:#"navContStoryboardID"];
[vc setModalPresentationStyle:UIModalPresentationCustom]; // optional
[vc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; // optional
[self presentViewController:vc animated:YES completion:nil];
Hope this helps you.

How to push Storyboard from loginviewcontroller which is an xib

I am having Loginview controller,I have created it with Xib and i want to push mainstoryboard on clicking loginbutton.
LoginViewController *lObjloginview = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
UINavigationController *lObjtempview = [[UINavigationController alloc] initWithRootViewController:lObjloginview];
self.window.rootViewController = lObjtempview;
[self.window makeKeyAndVisible];
This will add loginview from xib.but after pressing loginbutton I want to load storyboard.Can anyone help me in pushing mainstoryboard which has tabbar controller inside mainstoryboard to link xib.
Load the initial view controller from the storyboard and present it
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController * initialVC = [storyboard instantiateInitialViewController];
self.window.rootViewController = initialVC;
If you know a priori the class you're instantiating
UITabBarController * initialVC = (UITabBarController *)[storyboard instantiateInitialViewController];

Pushing UIViewController in navigationcontroller shows empty view

I am facing the problem that when I push my viewcontroller in the navigationcontroller all it does is changing the navigationbar and showing the standard background but no view is to be seen. My code for pushing the viewcontroller into the navigationcontroller looks like:
Viewcontroller1 *viewController = [[Viewcontroller1 alloc] autorelease];
[[self navigationController] pushViewController:viewController animated:YES];
But, if I initialise the viewcontroller by creating IBOutlets for it, it works just fine. But the reason why I am not doing that is because I later on needs to pass some parameters to the class on initialization.
Thanks for your time.
You have to initialise your view like
if you have xib then
Viewcontroller1 *viewController = [[[Viewcontroller1 alloc] initWithNibName:#"Viewcontroller1" bundle:nil]autorelease];
[[self navigationController] pushViewController:viewController animated:YES];
if you haven't xib
Viewcontroller1 *viewController = [[[Viewcontroller1 alloc] init]autorelease];
[[self navigationController] pushViewController:viewController animated:YES];

UINavigationBar and UITableView in Xcode 4.3.2

Did you notice that UINavigationBar is not set anymore when creating a UITableView, even after giving it a title or a button?
Now i'm going mad on how to put a navigation bar over my UITableView. It seems really impossible. I tried to add to my tableView a subview with the Navigation Bar, but seems worthless, because when I scroll down, the navigation bar scrolls down as wellm and it shouldn't.
Any ideas on how to implement it?
EDIT
Well, as always I went on File -> New -> File.. -> UITableView. Then i set a bit of code and when I wrote
self.navigationItem.title = #"MyTitle";
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
and tried to test on Simulator, no Navigation Bar appeared.
My init code:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = #"TabTitle";
self.tabBarItem.image = [UIImage imageNamed:#"img.png"];
self.view.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
}
return self;
}
I can't explain why it doesn't appear anymore. I also tried to create a new project and import my classes from a project where the navigation bar appeared, but same result there too.
EDIT2*
The app is a tabBased application.
Here is the code took from the App delegate used to set up the tabBar.
UIViewController *viewController1, *viewController4;
UITableViewController *viewController2, *viewController3;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[FirstViewController alloc] initWithNibName:#"First_iPhone" bundle:nil];
viewController2 = [[Tips alloc] initWithNibName:#"Table" bundle:nil];
viewController3 = [[Favorites alloc] initWithNibName:#"Test_iPhone" bundle:nil];
viewController4 = [[SecondViewController alloc] initWithNibName:#"Second_iPhone" bundle:nil];
}
You are initing an UITabBarController and set 4 UIViewControllers as the corresponding UITabbarViewControllers. Since two of them are normal UIViewControntroller and two are UITableViewController there can not be a navigation bar. You have to load the viewController where you'd like the navbar form a UINavigationController. The correct way would be (assuming vc3 is the one where you'd like the navbar):
UIViewController *viewController1, *viewController4;
UITableViewController *viewController2, viewController3;
UINavigationController *vc3NavController;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[FirstViewController alloc] initWithNibName:#"First_iPhone" bundle:nil];
viewController2 = [[Tips alloc] initWithNibName:#"Table" bundle:nil];
viewController3 = [[Favorites alloc] initWithNibName:#"Test_iPhone" bundle:nil];
vc3NavController = [[UINavigationController alloc] initWithRootViewController:viewController3];
viewController4 = [[SecondViewController alloc] initWithNibName:#"Second_iPhone" bundle:nil];
}
Then load the vc3NavController instead of viewController3 as the corresponding tab.
So you have: UITabBarController -> UINavigationController -> YourViewController
Maybe Creating a Navigation Interface will help you too.

Can a UITabBarController be a segue.destinationViewController?

I have a UITabBarController with three tabs: each is a navigation controller with a view controller embedded. Currently the tabController is the initial view controller. I would like to place an intro view controller with buttons that precedes the tabController, with buttons that segue to the tabController. I'm using Xcode 4.2 and storyboards.
Is this possible?
In my IntroViewController I call prepareForSegue. It is not working:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"tabSegue"]) {
FirstViewController *firstVC = [[FirstViewController alloc]init];
SecondViewController *secondVC = [[SecondViewController alloc] init];
ThirdViewController *thirdVC = [[ThirdViewController alloc]init];
self.tabBarController = segue.destinationViewController;
UINavigationController *navController1 = [[UINavigationController alloc]initWithRootViewController:firstVC];
UINavigationController *navController2 = [[UINavigationController alloc]initWithRootViewController:secondVC];
UINavigationController *navController3 = [[UINavigationController alloc]initWithRootViewController:thirdVC];
NSArray *tabViewArray = [NSArray arrayWithObjects:navController1,navController2,navController3, nil];
tabBarController.viewControllers = tabViewArray;
}
}
In summary, can you segue to a tabBarController?
As the comment states, I used self.tabBarController = segue.destinationViewController.
Thanks Ar No.
My situation was to pass object value from view 1 to 2.
NavControl - ViewController(1)
TabbarControl - NavControl - ViewController(2)