I'm trying to recreate a small iOS app that utilized nib files. I'm trying to replace the following line of code
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
with:
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController* viewController = [sb instantiateViewControllerWithIdentifier:#"viewController"]; self.window.rootViewController = self. viewController;
I'm getting the following error: * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard () doesn't contain a view controller with identifier 'viewController''
I got the latter code from a previous Stack Overflow question on a similar topic. Can someone please advise on what the issue I'm having is and how to proceed?
You need to name the view controller in your storyboard by giving it a storyboard id. I typically try to use something memorable like the name of the view controllers class so I don't have to look it up.
Related
I'm trying to add a new storyboard in Swift to an old Objective-C app:
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"MainStoryboard01" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:#"OnboardingViewController"];
[self presentViewController:vc animated:YES completion:NULL];
With Swift storyboard:
I'm always getting error:
'Could not find a storyboard named 'MainStoryboard01' in bundle NSBundle <.../Developer/CoreSimulator/Devices/753636C1-ABB5-4D6E-B184-5C4638FB2CE9/data/Containers/Bundle/Application/398410C0-BB2C-4574-B058-95D30F8D1B5D/Credit Call.app> (loaded)'
Calling swift classes like
TestClass *instance = [TestClass new];
[instance testFunction];
Normally works. Any idea how to call swift storyboard + it's swfit controller in Objective-C app?
// EDIT:
I finally get working this:
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Onboarding" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:#"MainStoryboard01"];
but on next line
[self presentViewController:vc animated:YES completion:NULL];
I get this error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyAppDelegate presentViewController:animated:completion:]: unrecognized selector sent to instance 0x6080000b3b60'
Any ideas? I need to replace this with the storyboard:
Registration *reg = [[Registration alloc] init];
registrationNav = [[UINavigationController alloc] initWithRootViewController:reg];
[reg release];
[self.mainBackgroundView addSubview:[registrationNav view]];
=> https://codepaste.net/jkfras I've added skeleton of the MyAppDelegate.m
You are making mistake here, MainStoryboard01 that you have set is Storyboard Identifer using that you can called instantiateViewControllerWithIdentifier. It is not the another storyboard name. So its should be simply like this.
//You need to put storyboard name here the check the image for more detail
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:#"MainStoryboard01"];
[self presentViewController:vc animated:YES completion:nil];
Edit: Try this way.
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:#"MainStoryboard01"];
[self.mainBackgroundView addSubview:[vc view]];
If you want to reference to a storyboard then you should use its name, so if your storyboard has a name "MyNewStoryboard" (MyNewStoryboard.storyboard) then the right way to create its reference is like this:
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"MyNewStoryboard" bundle:nil];
Don't use a storyboard ID here. Storyboard ID you just set in the controller's attributes is the identifier for your controller. So you can use it this way:
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:#"MainStoryboard01"];
Change your new controller's Storyboard ID to something more informative, so for example "OnboardingViewController", and then after putting your storyboard file name in your first line your code should be fine.
I try to navigate to certain ViewController after I get remote Notification
It crashes after this code any help please
My storyboard like this
SWRevealViewController -> NavViewController -> UIViewController
I want to reach this UIViewController
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
UIStoryboard *storyboard =[UIStoryboard storyboardWithName:#"Main" bundle:nil];
// my ViewController I want navigate to UITableViewController call home_tableview
Home_tableView *home =[storyboard instantiateViewControllerWithIdentifier:#"home_view"];
[(UINavigationController *)self.window.rootViewController pushViewController:home animated:NO];
}
The Error I get
2015-01-20 13:04:14.379 SchoolLink[1304:416727] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:(0x25bd749f 0x3338dc8b 0x25af30b3 0x2909d06b 0x11d48f 0x29099d0f 0x29099a7d 0x2909f953 0x2910643d 0x111dbd 0x2930286b 0x292fa54d 0x2c3680d1 0x25b9dd7d 0x25b9d041 0x25b9bb7b 0x25ae93c1 0x25ae91d3 0x2cee70a9 0x290f8fa1 0x12b7ad 0x3390daaf)
libc++abi.dylib: terminating with
I suppose you have an UINavigationController in your storyboard which embeds your view controllers.
If that's the case, your code should work without any issues.
I've tested it in a new project with two view controllers and one navigation controller as the initial view and everything is fine.
If you're certain that you have all the storyboard identifiers right, and that your initial View in Interface Builder is an UINavigationController that embeds all of your ViewControllers, then you have some issues elsewhere, not in the code you've pasted in.
Since your error is related to insertObjectAtIndex: I believe there's some data you instantiate your UITableViewController with in the normal workflow of the app (when segueing to it) and when you try to present the UITableView controller in a clean state from a notification, that data is missing, hence the crash.
Check where you try to add an object to an array at a given index.
The problem is either in the class that receives the notification (I guess it's your AppDelegate class), either in the UITableViewController class, somewhere in the initialization.
Try
Home_tableView *home =[storyboard instantiateViewControllerWithIdentifier:#"home_view"];
[self.window setRootViewController:home]
[self.window makeKeyAndVisible];
Please try this:
UIStoryboard *storyboard =[UIStoryboard storyboardWithName:#"Main" bundle:nil];
Home_tableView*svc = [storyboard instantiateViewControllerWithIdentifier:#"home_view"];
// Configure the new view controller here.
[self presentViewController:svc animated:YES completion:nil];
I'm trying to use PKRevealController with Storyboard. This is how my AppDelegate looks at startup
MainNavController* navController = [[UIStoryboard storyboardWithName:#"Main" bundle:nil]instantiateViewControllerWithIdentifier:#"MainNavController"];
MainViewController* mainViewController = [[UIStoryboard storyboardWithName:#"Main" bundle:nil]instantiateViewControllerWithIdentifier:#"MainViewController"];
LeftViewController* leftViewController = [[UIStoryboard storyboardWithName:#"Main" bundle:nil]instantiateViewControllerWithIdentifier:#"LeftViewController"];
PKRevealController *revealController = [PKRevealController revealControllerWithFrontViewController:navController leftViewController:leftViewController];
revealController.animationDuration = 0.25;
revealController.delegate = self;
self.window.rootViewController = revealController;
So that seems to work fine, and the App Launches with no problems, but when I swipe to the right, the left view controller shows up and then crashes with this error:
'NSInvalidArgumentException', reason: '-[PKAnimation pk_identifier]: unrecognized selector sent to instance
I don't know how to solve this.
This may be an importation error. Check here https://github.com/pkluz/PKRevealController/blob/master/Documentation/USAGE.md to see how to import correctly, if you import it as a static library make sure to reproduce all steps!
Hey together,
I am calling a void with some parameters from the AppDelegate on my main view.
This is done if a push notification is received:
MainViewController *mainView = [[MainViewController alloc] init];
[mainView showPushView:pushDataObject];
The called void # the MainView doing some data operating stuff and after that it should load the pushView:
- (void)showPushView: (PFObject *)pushDataObject {
NSLog(#"Push Data object transfered %#", pushDataObject);
pushItem = pushDataObject;
//All working fine to this point
[self performSegueWithIdentifier:#"showPushObject" sender:self];
}
Now the problem is that the app is crashing at [self performSegueWithIdentifier:#"showPushObject" sender:self]; with this Error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'Receiver (<MainViewController: 0x145b80e0>) has no segue with identifier 'showPushObject''
*** First throw call stack:
(0x2e51fe83 0x3887c6c7 0x30f656d9 0xbeb11 0xb2a23 0x1745f7 0x38d610c3 0x38d610af 0x38d639a9 0x2e4ea5b1 0x2e4e8e7d 0x2e453471 0x2e453253 0x3318d2eb 0x30d08845 0xafecd 0x38d75ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
I think that there is a problem because I call the void from the AppDelegate, am I right?
Those anyone know a fix for that problem?
Thanks a lot!
Best regards from Germany :)
P.S. If I call [self performSegueWithIdentifier:#"showPushObject" sender:self]; with a button or something on the MainViewController all working fine... :/
In order for the segue to work, you need to have the storyboard loaded in the mainView when you start it that way. Try instead something like this:
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *firstViewController = [storyboard instantiateViewControllerWithIdentifier:#"kYourMainViewControllerIdentifier"];
self.window.rootViewController = firstViewController;
[self.window makeKeyAndVisible];
Remember to give an identifier to your root view controller and change it in this piece of code.
Your problem is this line:
MainViewController *mainView = [[MainViewController alloc] init];
because it means that the mainView instance doesn't have a storyboard (so it can't have any segues).
When you run it from a button the controller instance must have been created from a storyboard.
So, to fix, load the storyboard and instantiate mainView from it. Then the segue will work.
UIStoryboard *storyboard4Inch = [UIStoryboard storyboardWithName:#"Storyboard4Inch" bundle:nil];
UIViewController *mainViewController = [storyboard4Inch instantiateViewControllerWithIdentifier:#"MainViewController"];
[mainViewController showPushView:pushDataObject];
I have a project that uses nib files, no storyboards. Depending on the app settings I need to display a different screen than what is being displayed now when the app is launched. I created this view as a storyboard in Interface Builder. In the main view controller's viewWilllAppear methodwhen certain conditions are true, I am trying to load the new storyboard and view controller:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"IncompleteSettings.storyboard" bundle: [NSBundle bundleWithIdentifier:#"Convention"]];
IncompleteSetingsViewController *vc = [storyboard instantiateInitialViewController];
I have tried passing nil and [NSBundle mainBundle] to the bundle argument.
I get this error:
08-09 11:38:39.188 Convention[17091:11603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'IncompleteSettings.storyboard' in bundle NSBundle (loaded)'
Project Details:
You shouldn't add the extension in the name of the storyboard:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"IncompleteSettings" bundle:nil];