Blank view after pushViewController - ios

Returning to iOS development after a year break, and its all mayhem.
When executing the 3 lines of code below, i see the screenshot of the emulator below.
I've also attempted to add the LoginForm view controller as the root view controller, as it should, except i also see a blank screen.
As shown in the screenshot of xcode, the naming all matches up. All the constraints are also blue.
I've included a NSLog in the viewDidLoad of the LoginForm, that i have seen log at points, but still nothing is displayed.
What am i missing, or doing wrong? I've got nothing from errors to work with.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *view = [storyboard instantiateViewControllerWithIdentifier:#"LoginForm"];
[self.navigationController pushViewController:view animated:YES ];

Try using
[self presentViewController:myVC animated:NO completion:nil];
Because your storyboard doesn't seem to be using navigation contoller.

If you Have Xib File
Viewcontroller1 *viewController = [[Viewcontroller1 alloc]
initWithNibName:#"Viewcontroller1" bundle:nil];
[[self navigationController] pushViewController:viewController animated:YES];
if you have Storyboard
Viewcontroller1*vc=[self.storyboard instantiateViewControllerWithIdentifier:#"Viewcontroller1"];
[self.navigationController pushViewController:vc animated:YES];

Related

Creating a replace segue to a detail view on iPad split screen programmatically

I've got the iPhone working fine with creating a segue programmatically.
e.g.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone"
bundle:nil];
FooBarViewController *foobarViewController = (FooBarViewController *)[storyboard instantiateViewControllerWithIdentifier:#"foobarViewControllerID”];
[self.navigationController pushViewController:foobarViewController animated:YES];
Now I'm trying to do something similar on the iPad storyboard.
The goal being to programmatically change the detail view to a view on the storyboard.
I thought maybe:
[self.splitViewController.navigationController presentViewController:foorbarViewController animated:NO completion:nil];
However this doesn't work. Any suggestions?
I believe I've solved my own question with the following function:
- (void) presentDetailView : (UIViewController *) viewcontroller {
UINavigationController *detailNavCtrl = [[UINavigationController alloc] initWithRootViewController:viewcontroller];
detailNavCtrl.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
detailNavCtrl.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[[[self.splitViewController viewControllers] lastObject] presentViewController:detailNavCtrl animated:NO completion:nil];
}

Confused about storyboards and pushing programmatically ios Objective C

I am really confused about the relationship between storyboards and pushing to views programmatically.
I am using SWRevealViewController to display a menu of items.
If I push to the storyboard using
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
PhotosViewController *controller = [storyboard instantiateViewControllerWithIdentifier:#"PhotosViewController"];
[self presentModalViewController:controller animated:YES];
[self.navigationController pushViewController:controller animated:YES];
All of the information in my storyboard is displayed but there is no "back" button to the SWRevealViewController.
If I push to the view controller using
PhotosViewController *frontViewController = [[StreamScreen alloc] init];
newFrontController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
Then I can view everything that I have added programmatically but nothing from the storyboard.
My question is how can I access things from both storyboard and things Ive added programmatically.
if you present the view controller then it will not give you default back button because when you present a controller it will not added in navigation stack of NavigationController so it won't give you that option.
If you want push controller do not use presentModalViewController.
Try like below
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
PhotosViewController *controller = [storyboard instantiateViewControllerWithIdentifier:#"PhotosViewController"];
[self.navigationController pushViewController:controller animated:YES];
and if you want to present controller then create manually add a back button like we have default in navigation back button and on it's click write below code to dismiss the controller.
[self dismissViewControllerAnimated:YES];
Hope this helps you.

How to dismiss view controller if it presented from app delegate?

So I'm trying to figure out deeplinking. I have successfully gotten my app to recognize and run code I want it to depending on the path in the URL. Now when I present a View, it shows but can't get the back button or any way to dismiss it to work. Here's the code in my appdelegate:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
BuyPremiumViewController *premiumViewController = [storyboard instantiateViewControllerWithIdentifier:#"BuyPremium"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:premiumViewController];
[self.window makeKeyAndVisible];
[self.window.rootViewController presentViewController:navigationController animated:YES completion:NULL];
The reason I use a UINavigationController is to have the nav title and back button show in the presented view. Thing is, it is not working. Here is the code that runs when the back button is tapped in the presented view:
- (void)backButton {
NSLog(#"this ran"); //check if actually ran
[self.navigationController popToRootViewControllerAnimated:YES];
}
Being at it for a hours now, help?
Try to use this code:
- (void)backButton
{
NSLog(#"this ran"); //check if actually ran
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}

iOS 7 presentViewController shows black screen and SIGABRT

I use two buttons on right UIBARBUTTON by writing code in the method[ViewDidLoad].
http://i.stack.imgur.com/VcOEW.png
http://i.stack.imgur.com/vG3eT.png
http://i.stack.imgur.com/f0xsB.png
I want to use +plus button to move to AddNameViewController but it results in a Fail[sigabrt].
http://i.stack.imgur.com/MBq2m.png
http://i.stack.imgur.com/Hdw8T.png
I think the error is in the following code.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
AddNameViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:#"AddNameViewController.m"];
[sfvc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:sfvc animated:YES completion:nil];
Change this:
AddNameViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:#"AddNameViewController.m"]
For this:
AddNameViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:#"AddNameViewController"]
You need the name of the View Controller, not the file.
Like Antonio said, you need the correct identifier for your view controller. The reason it crashes is because you get a nil view controller pointer back from the instantiateViewControllerWithIdentifier: call and passing nil to presentViewController:animated:completion: causes your crash.
check this
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
AddNameViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:#"AddNameViewController"];
[sfvc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:sfvc animated:YES completion:nil];
and add identifier AddNameViewController in storyboard ID
Sorry, I did not check carefully before asking. Because I tried many ways to improve it. Although, I change AddNameViewController.m to AddNameViewController ,
It still show sigabrt.

Transition between two UIViewControllers with no animation

From my appDelegate I load the the homeScreen ViewController like this:
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
UIViewController *controller = [sb instantiateViewControllerWithIdentifier:#"HomeScreen"];
[self.window setRootViewController:controller];
The app only ever then changes between my 'homeScreen' and 'PlayViewController' ViewControllers and that is done like this:
PlayViewControlller* vc = [self.storyboard instantiateViewControllerWithIdentifier:#"PlayViewController"];
[self presentModalViewController:vc animated:NO];
and this
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
UIViewController *controller = [sb instantiateViewControllerWithIdentifier:#"HomeScreen"];
[self presentModalViewController:controller animated:NO];
respectively.
This all works fine. I am able to switch between the viewcontrollers with uibuttons and the above code. However, I'm not sure what causes this, it happens after I've switched between the two viewcontrollers a few times, but the transition starts to get animated and they start twirling when switching.
Ok so I'm trying to narrow down the problem and see what's causing it. I think its the other animation blocks that I'm using in my app. But there's a lot there so don't know exactly what it is.
OK so I found the line of code that was causing this if anyone happens to find themselves in the same situation.
[UIView beginAnimations:#"Move" context:NULL];

Resources