AppDelegate doesn't init viewController right - iphone

I am using PaperFoldMenuController to create a cool SlideMenu in my App.
In the AppDelegate I define the viewControllers and add them to the SlideMenu Array:
// Init viewControllers
RootViewController *rootViewController = [[RootViewController alloc] init];
LivetickerViewController *livetickerViewController = [[LivetickerViewController alloc] init];
// Add view controllers to array
[viewControllers addObject:rootNavController];
[viewControllers addObject:livetickerNavController];
// Add to PaperFoldView
[_menuController setViewControllers:viewControllers];
I use a storyboard for designing most parts of the LivetickerViewController. But all changes are not shown. I checked that Storyboard is connected with the view.
What is the problem in the code ?

If you've designed your LivetickerViewController in the storyboard, then you need to get it from the storyboard not with alloc init.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
LivetickerViewController *livetickerViewController = [storyboard instantiateViewControllerWithIdentifier:#"livetickerViewController"];
Make sure that the name of the storyboard is what is actually in your project, and that you have given the view controller an identifier that matches what you pass in the instantiateViewControllerWithIdentifier: method.
If you made rootViewController in the storyboard, you should do the same thing with it.

Related

present a UIviewcontroller programmatically from UINavigationController with Storyboard

My question: How can I switch between viewcontrollers with 1 rootNavigationController in code, while maintaining customization I set in Storyboard and data that I load up in my viewcontrollers?
Currently I am implementing REMenu, which provides a simple dropdown tableview to change views with. When one of those cells is pressed in the dropdown, I want to switch my view. For example, if I press "Home", I want to go to my MasterViewController The method to switch views is called from within rootnavigationcontroller.m, and looks like the following:
REMenuItem *homeItem = [[REMenuItem alloc] initWithTitle:#"Home"
subtitle:#"Return to Home Screen"
image:[UIImage imageNamed:#"Icon_Home"]
highlightedImage:nil
action:^(REMenuItem *item) {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UINavigationController *vc = [sb instantiateViewControllerWithIdentifier:#"myNewTableView"];
// vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:vc animated:NO completion:nil];
}];
Clearly, however, something is wrong with this implementation, because it ignores the UI Customization I made in Storyboard, as well as a datacontroller I invoke in MasterViewController.m Any help on this matter would be greatly appreciated!

How to get an instance of my view controller from the app delegate, storyboards, iOS6

Trying to "instantiate" my initial view controller from the app delegate. I trying to populate an NSMutableArray from the app delegate. A property of the view controller "myMutabelArray" gets an array that is created within the app delegate. With the code below the array is uneffected, even though it's count is 4 (has four objects), as created in the app delegate.
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle: nil];
ViewController *controller = (ViewController*)[mainStoryboard instantiateInitialViewController];
controller.myMutableArray = mutableArrayCreatedInAppDelegate;
When I log the count from within the AppDelegate I get 4.
When I log the count from within the ViewController I get 0.
I also tried the following which makes me suspect that I am not getting a pointer to the view controller as needed.
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle: nil];
ViewController *controller = (ViewController*)[mainStoryboard instantiateInitialViewController];
[controller.view setBackgroundColor:[UIColor lightGrayColor]];
Try the following:
ViewController *controller = (ViewController*)self.window.rootViewController;
It will return the initial view controller of the main storyboard.

How to create a UINavigationController with a UITableViewController as root, all within Interface Builder?

1) In my app delegate I create the root view controller which is a navigation controller:
self.navigationController = [[UINavigationController alloc] initWithNibName:#"RootNavigationController" bundle:nil];
self.window.rootViewController = self.navigationController;
2) "RootNavigationController.xib" creates a UINavigationController. It also defines a root view controller, which is a CatsViewController : UITableViewController. There is a CatsViewController file and a "CatsViewController.xib" with a UITableViewController root object. Like you can see in this screenshot I set the NIB Name accordingly:
The problem is, Xcode doesn't let me select CatsViewController from the dropdown even if there is a CatsViewController.xib file. I want the XIB for my UINavigationController to create an instance of CatsViewController as it's root, and I want to configure this root controller through a separate nib file.
Xcode warns:
Is there a way to do it?
The error you are getting is due to didFinishLaunchingWithOptions method in the AppDelegate trying to initialize the window and not just returning YES.
also in your code change the RootNavigationController, like:
self.navigationController = [[UINavigationController alloc] initWithNibName:#"RootNavigationController" bundle:nil];
change it to
self.navigationController = [[UINavigationController alloc] initWithNibName:#"CatsViewController" bundle:nil];

Application tried to push a nil view controller on target <UINavigationController>

I have a UITableView which is assigned to a NavigationController identified by "ArticleNavigation". In my delegate (didFinishLaunchingWithOptions method) I tried to create a UItabBar programatically:
main_tab =[[UITabBarController alloc] init];
viewController1 = [[ListViewController alloc]init];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UINavigationController * nav1=[[storyboard instantiateViewControllerWithIdentifier:#"ArticleNavigation"]initWithRootViewController:viewController1];
tabs_array=[[NSArray alloc]initWithObjects:nav1, nil];
main_tab.viewControllers=tabs_array;
self.window.rootViewController=main_tab;
When I run my app and click on a cell I obtain this error:
Application tried to push a nil view controller on target <UINavigationController>
Any guesses please?

View won't switch properly

I'm trying to switch views in an iPhone application, but whenever I click on the button to bring up the second view, all I get is a blank screen, even though I've filled the view with buttons and whatnot.
I've checked the second ViewController in my storyboard file and its custom class is the one that it needs to be (When I originally created the second ViewController class a new interface file came with it, which I promptly deleted). What might I be doing wrong?
- (IBAction)Transition_NEXT:(id)sender
{
nextViewController = [[NextViewController alloc]
initWithNibName:#"NextViewController"
bundle:[NSBundle mainBundle]];
[self presentModalViewController:nextViewController animated:NO];
}
I don't think you're using Storyboards correctly. You shouldn't be using initWithNibName, as that's the old method of instantiating a view controller. Try using the new instantiateViewControllerWithIdentifier like so:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:[NSBundle mainBundle]];
UIViewController *nextView = [storyboard instantiateViewControllerWithIdentifier:#"NextViewController"];
[self.view presentModalViewController:nextView animated:YES];
If you already have a reference to your storyboard in your controller, then you shouldn't initialize a new one, but instead you should just use the reference you have.
UIViewController *nextView = [self.storyboard instantiateViewControllerWithIdentifier:#"NextViewController"];
[self.view presentModalViewController:nextView animated:YES];