I design a soft Pin.
You can put 4 numbers twice and it will be your code. When you finished code assignment. The view will present segue (kind: Present Modally) to show another viewController.
Due to convenient, I would like to reset the View controller.
The Best way I found on the stack overflow is to reset rootViewController in the Appdelegate
Solution Here
When I follow the steps, I got an error below :
The Console shows :
Maybe the problem is the design in my storyboard
The upper one is original viewController
Can anyone figure out what's wrong with my code?
Thanks a lot!!!
The problem is from your Storyboard : you don't have a view controller with a StoryBoard ID EnterPinViewController.
Go to your Storyboard, select the controller and on side panel Utilities check the StoryBoard ID value.
Or change instantiateViewControllerWithIdentifier parameter with the one matching the Storyboard Identifier of your view controller.
Click on your controller in storyboard.
In right side panel go to identity Inspector (3rd button)
Set Storyboard ID to EnterPinViewController
You are all set to go further now!!
Related
I am developing an application with iOS 9 based SDK , this is my first time I am working with Storyboards , I have 20 view controllers, each scene has Next / Previous buttons to go back and forward . I have a huge problem with going forward !. If I move from scene 1 to for example to scene 15 I received memory warning and then application crashes . I have searched and it seems there is method called unwind segue but it seems this is for going back ! it's something like dissMiss method .
I connect each scene with line in Interface Builder :
Here is segue's setting :
I would be grateful if you help me out .
EDITED :
I tried to present a view controller programmatically but result was the same ! .
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
WhatIsDino *vc = (WhatIsDino*)[mainStoryboard instantiateViewControllerWithIdentifier:#"WID"];
[self presentViewController:vc animated:YES completion:nil];
Seems like it's a problem of wrong approach, and not the storyboard.
Let me guess, since before storyboard you used to change your app's rootViewController to the next/previous screen once you tap on the arrow button. So previous screen are released and deallocated from memory once you set a new rootViewController.
And now you're presenting every next view controller modally, which involved creating new UIWindow and loads all the hierarchy of you screen and keeps previous underneath the new one so it holds the memory and you're getting out of memory crash.
Well, you can do rootViewController approach with a storyboard too since it's just another way to manage your screens while development. Storyboard offers additional features like segues, static table view cells, general tint color and so on. [UIStoryboard -instantiateViewControllerWithIdentifier:] is the method you might find interesting.
But I'd rather recommend you to check out the UIPageViewController, it's like a container for the screens. Unfortunately, it cannot have the segues to your scenes (because of the special way segues work) so you have to use -instantiateViewControllerWithIdentifier: method anyway. You can treat inner view controllers of UIPageViewController as you do with rootViewController before.
You can also navigate without segue and Its easy way I think.
If you want to navigate from Class1 to Class 2 then follow these steps.
1) In Class 1, Import Class2.
2) In your button Action, Write this code.
Class2 *next = [self.storyboard instantiateViewControllerWithIdentifier:#"Class2 Identifier name"];
[self.navigationController pushViewController:next animated:YES];
Do not forget to give Identifier name in story board that is "Storyboard ID" in Attribute inspector of particular class.
No need to add Segue,Your storyboard would look clean.
The problem is that you are adding view controller after view controller with modal presentation. That causes each view controller to be added on top of the previous one, and all of them accumulate, using more and more memory.
Using a navigation controller and a push also piles the view controllers on top of each other.
You will have this problem if you use storyboards, nibs, or create the view controllers manually.
If you have a design where the user can move through a large series of view controllers then you probably want to dismiss the previous one before pushing/presenting a new one.
You can probably dismiss the previous view controller without animation and then present the new view controller each time you want to display a new one and avoid the memory issue. i'd have to experiment with it to get the effect I was after, but that's what I would suggest.
I can't find an answer to this seemingly basic question. Let's say I have a storyboard with two view controllers A and B and a segue transition from one to another. Now, I created a different view controller C and now would like to redirect the existing segue from A to C.
I Ctrl dragged it, command dragged it, etc. it does not seem to work. In the real app, I have way too many segues to try to re-create them from scratch. Is there an easier way?
This question is not a duplicate as flagged since I'm trying to reuse existing segue, not direct to a different controller.
Thanks!
Option 1,using XML file
First,right click the Storyboard file.Then select open as Source
Code
Search segue,then change the destination id
<segue destination="Esd-4c-JQq" kind="show" id="Jnu-RW-1O5"/>
Option 2,using Interface Builder
First, selected the segue source ViewController
Second,Create a same segue(Control+drag),like picture shows
Now,you have two same segue,
You just need to delete the old one
You can drag segue from ViewController icon at the top of ViewController to other Controllers.
Just give identifier to segue by clicking segue pointer on storyboard and then opening attribute inspector and finally you have to do just that code.
Case 1: Push Segue to B from A
[self performSegueWithIdentifier:#"PushB" sender:self]; //PushB is segue identifier
Case 2: Push Segue to C from A
[self performSegueWithIdentifier:#"PushC" sender:self];
Note : You must have Navigation Controller as initial point of storyboard before performing performSegueWithIdentifier.
Hope this will help.
Delete the previous one from A to B and then recreate new one from A to C.
Hope it helps.
I want to move to another viewcontroller in another storyboard and the view controller im in is not embedded in a navigationctroller.
Normally i would just instantiate the viewcontroller and push it to the navigationcontroller stack but since this is not possible i dont know what to do, and I cant seem to find any help on this.
Any suggestions?
It depends on what you're trying to achieve in the app, but a few options are: present it as a modal controller, create your own custom type of segue, replace the root controller in the app's window....
I have a TabBar with 3 buttons, the 2nd and 3nd buttons have a segue to the same controller, which should show different info depending on one param.
I've overridden TabBar class to implement.-
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender;
to be able to add my param just before performing the segue, but I must be missing something obvious because prepareForSegue is not getting called.
Is there anyway to achieve this without programmatically creating custom segues?
According to me you cannot interact with segue linked as "root" controllers.
Those segue are not "getting called" as they don't represent a transition between two view controllers.
If you look at Interface Builder there is no settings available for that kind of segue.
I had a similar issue in one of my project and solve the issue by setting the controllers programmatically. After that you add your view controller in storyboard and set a "Storyboard ID" in the right hand panel.
Then, you can instantiate your view controller by doing
[self.storyboard instantiateViewControllerWithIdentifier:#"YOUR_VIEW_CONTROLLER_ID"];
And affect them to your UITabBarController by doing
[self setViewControllers:viewControllers];
Hope this help!
Not sure if it's the best practice, but I finally ended up getting the selected tab from my controllers.-
self.tabBarController.selectedIndex
This simple way, I know what info should I show, without changing my storyboard segues.
I'm new working with Storyboards, so I'd appreciate any help!
I have a Settings view controller which should only appear if no previous settings exist. If those have been set, a different vc (the main one) is loaded.
I tried using the method in the attached image, but I'm not sure that's correct...
In the RootViewController I'm testing in viewDidLoad if settings were previously set or not, and am triggering the Segue with either ShowMain or ShowSettings as identifiers.
[self performSegueWithIdentifier:#"ShowMain" sender:self];
Of course RootViewController shows up in the NavigationController hierarchy (with the back button showing), which I don't want.
How should I be going about this?
Tia!
S.
If, as it seems, the RootViewController only exists to decide which real controller to show, I'd suggest you get rid of it. Your main controller can be set as the first controller and have the settings logic in its viewDidLoad. Then, make your settings controller be presented using a modal segue. Once you're finished with the settings (if necessary), dismiss it and you're back to the main one.