iOS 7 presentViewController shows black screen and SIGABRT - ios

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.

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];
}

Load View if load data complete

I change the view programmatically like that:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"edit"];
vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:vc animated:YES completion:nil];
The problem is, that when I change the view, that the data are not completely loaded. How can I say, that it should wait, until the data is loaded?

UIStoryboard with object

I have multiple storyboards within my app. I want to pass an object when a new storyboard is opened.
I'am doing this:
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"SetupStoryboard" bundle:[NSBundle mainBundle]];
UINavigationController* initialHelpView = [storyboard instantiateInitialViewController];
SetupViewController *setup = (SetupViewController*) [initialHelpView topViewController];
setup.data = self.data;
initialHelpView.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:initialHelpView animated:YES completion:nil];
But when the storyboard is presented the setup.data is nil in viewDidLoad, viewWillAppear etc of the SetupViewController...
Why is that?
I don't see anything wrong with this code. Problem may be elsewhere.

Passing managedObjectContext via presentViewController

I am trying the "pass the baton" method for passing the managedObjectContext (MOC) thru multiple views. I have it successfully passed to the rootViewController. From there I move to a tabBarController via presentViewController. I can't seem to find a way to pass the MOC when the tabBarController is pushed.
AppDelegate.m
UIViewController *navigationController = (UIViewController *)self.window.rootViewController;
MyViewController *controller = (MyViewController *) navigationController;
controller.managedObjectContext = managedObjectStore.mainQueueManagedObjectContext;
The main view controller is basically a start up screen that will kick you into a login screen or if you are already logged in, to the tabBarController. Below is where I transition to the tabBarController from within the viewDidAppear method.
MyViewController.m
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
UIViewController *mainTabVC = [storyboard instantiateViewControllerWithIdentifier:#"mainTabVC"];
[mainTabVC setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:mainTabVC animated:NO completion:nil];
The tabBarController in the storyboard has the identifier "mainTabVC".
I've tried lines like
MyTabBarController.managedObjectContext = self.managedObjectContext;
but I get the error Property 'MOC' not found on object of type MyTabBarController even though I do have the property declared in MyTabBarController.h
Could someone show me a line of code that I can throw in this segue to push the MOC to the tab bar controller.
BTW- I'm utilizing RestKit in this app if that changes the way I should be handling this please let me know.
*****Solution********
To make things clear for any other new guys with the same question. I went from this:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
UIViewController *mainTabVC = [storyboard instantiateViewControllerWithIdentifier:#"mainTabVC"];
[mainTabVC setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:mainTabVC animated:NO completion:nil];
To this:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
MyTabBarViewController *mainTabVC = [storyboard instantiateViewControllerWithIdentifier:#"mainTabVC"];
mainTabVC.managedObjectContext = self.managedObjectContext;
[mainTabVC setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:mainTabVC animated:NO completion:nil];
Notice the assignment in the third line and using MyTabBarViewController instead of UIViewController in the second line. BIG thanks again to rdelmar!
Your code is somewhat confusing. Is MyTabBarController the class? It looks like mainTabVC is your instance. You should use that rather than the class, and you should change the type when you instantiate mainTabVC to MyTabBarController, instead of UITabBarController. You also don't need to get the storyboard the way you do, you can just use self.storyboard.
MyTabBarController *mainTabVC = [self.storyboard instantiateViewControllerWithIdentifier:#"mainTabVC"];
mainTabVC.managedObjectContext = self.managedObjectContext;
[mainTabVC setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:mainTabVC animated:NO completion:nil];

presentViewController shows black page

- (IBAction)submitButtonClicked:(id)sender{
NSLog(#"here");
SuccessOrFailViewController *sfvc = [[SuccessOrFailViewController alloc] init];
[self presentViewController:sfvc animated:NO completion:NULL];
}
I am trying to open a new page when a user clicks the submit button in the app. However, this opens completely black screen with nothing on it. How do I make it open the viewController instead ?
You are not entering the nib name for the user Interface:
SuccessOrFailViewController *sfvc = [[SuccessOrFailViewController alloc] initWithNibName:#"SuccessOrFailViewController" bundle:nil];
[self presentViewController:sfvc animated:NO completion:NULL];
For storyboard this is the way to go:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
SuccessOrFailViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:#"SuccessOrFailViewController"];
[sfvc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:sfvc animated:YES];
Swift
var next = self.storyboard?.instantiateViewControllerWithIdentifier("DashboardController") as! DashboardController
self.presentViewController(next, animated: true, completion: nil)
don't forget to set ViewController StoryBoard Id in StoryBoard -> identity inspector
Incase anyone else finds this, make sure you haven't set self.view.backgroundColor = UIColor.clearColor() in the view to be shown... This solved it for me.
For Storyboard iOS7
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
SuccessOrFailViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:#"SuccessOrFailViewController"];
[sfvc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:sfvc animated:YES completion:nil];
I've had this happen after adding and deleting View Controllers in the Storyboard and forgetting to update the View Controller with the latest Storyboard identifier.
For example, if you are programmatically moving to a new View Controller, like this (note Identifier in the code is "FirstUserVC"):
let firstLaunch = (storyboard?.instantiateViewControllerWithIdentifier("FirstUserVC"))! as UIViewController
self.navigationController?.pushViewController(firstLaunch, animated: true)
The make sure in Interface Builder you have the Storyboard ID set like this with FirstUserVC listed in the Identity for Storyboard ID:

Resources