iOS GameOver screen does not appear - ios

We have an error with our iOS game. The gameover screen (containing the score) doesn't come up after losing the game, as it just hangs up. Can anyone suggest what could be the problem and how can we fix this?
We are currently testing and we are not sure if this is the case because of the code or the test settings? But so far the Xcode doesn't show any errors.
Thanks for your help.

Open a view from a normal class:
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:storyBoardName bundle:nil];
UIViewController *viewController = [storyBoard instantiateViewControllerWithIdentifier:StoryboardID];
[self presentViewController:viewController animated:NO completion:nil];
Edit these strings to:
storyBoardName = The name of your storyboard.
storyBoardID = The StoryBoardID of your ViewController.
Open a view from the AppDelegate
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:storyBoardName bundle:nil];
UIViewController *viewController = [storyBoard instantiateViewControllerWithIdentifier:storyBoardID];
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
Edit these strings to:
storyBoardName = The name of your storyboard.
storyBoardID = The StoryBoardID of your ViewController.
Other information
How to get the storyBoardName?
If your StoryBoard is called Main.storyboard Main is the title.
If your StoryBoard is called MyName.storyboard MyName is the title
How to set a StoryBoardID?
Select your ViewController. Your View must now be highlighted blue. Go to the identity inspector and under identity you'll find StoryBoardID. Set it to whatever you like.
If it still doesn't work when you use this code you have put in the wrong variables, or there's an unknown error.

Related

intially select sw_front view controller swrevealviewcontroller

I have two profile in my app. So after some initial profile setup, my app will start with different screens (firstVC or SecondVC).
So based on the initial (Consider Appdelegate :didfinish Method) setup, i wish to select "sw_front" to be firstVC or secondVC.
Every time firstVC is loaded first. If i wish to open SecondVC first, i tried is very simlpe code in viewWillAppear Method, may be incorrect:
UIViewController * sec = [self.storyboard instantiateViewControllerWithIdentifier:#"SecondID"];
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:sec];
[self.revealViewController pushFrontViewController:nav animated:YES];
The issue is app directly enters firstVC, but I want it to enter directly in FirstVC or SecondVC, when needed.
Thanks, any help appreciated :)
May be you are coding wrong.Try below code when you are pushing.
UIStoryboard *storyboard = nil;
storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
SWRevealViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"SecondID"];
[self.navigationController pushViewController:vc animated:YES];

Programmatically load ViewController from Storyboard in app with multiple storyboards

I am working on an application that is transitioning to having multiple storyboards for different sections of the app. They are linked together by programmatically loading them at the appropriate times.
In a function for when a UIButton is tapped, it should programmatically load a storyboard. The code is like so:
- (void)loginTapped:(id)sender {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Home.storyboard" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:#"homeStoryboard"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];
}
The storyboard is named the name listed in in the function:
and is listed as a target in the project settings appropriately:
and has the appropriate ID like so:
However, even after setting all this I get the error:
'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'Home.storyboard' in bundle NSBundle
I have tried to follow the advice from this post here, but nothing has worked. How do I get this storyboard to load?
The solution (as mentioned in the comments above) is to not include the .storyboard when providing the name of the storyboard.
Old
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Home.storyboard" bundle:nil];
New
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Home" bundle:nil];
Try this:
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Home" bundle:nil];
To call any ViewController programmatically in ios using Objective c:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:Home bundle:nil];
yourDestinationViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#homeStoryboard];
[self presentViewController:vc animated:YES completed:^{}];
yourDestinationViewController in the code is your view controller.h file.
You want to import that viewcontroller.h file in your program, where you want to call the View controller programmatically.
and to create the property like below,
#import "viewcontroller.h"
#property viewController *yourDestinationViewController;

How to navigate to a view controller on a new storyboard file in objective-c

I got a source code for an existing app. throughout the app the developer didn't use storyboard for the user interface but rather he used interface builder xib files. As a new developer, i don't know how to develop iOS apps in xcode using xib files for viewcontrollers, i learnt the storyboard way. Now I want to add more screens to the apps source code, i created a new storyboard file to define my new screens, how do I navigate to the entry point of this new storyboard from a button action i defined in one of the xib files so that i can easily implement my features.
while searching i got some suggestions like this one
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"newStoryboard_iPhone" bundle:nil];
MyNewViewController *myVC = (MyNewViewController *)[storyboard instantiateViewControllerWithIdentifier:#"myViewCont"];
but i dont think i understand how to implement this even if this can be in a button IBAction method. and besides subsequent navigations would be segues through the view controllers i define in the new storyboard
It's right suggestion.
You should get storyboard object by its name. Then you should create your viewController using [storyboard instantiateViewControllerWithIdentifier:#"..."];
Then you may navigate to your new VC using appropriate navigation method. For example:
[self.navigationController pushViewController:vc animated:YES]
ViewController identifier you should set in Interface Builder under section "Identity Inspector" in field "Storyboard ID".
That code you should place in IBAction method. But better would be to extract it in separate method. Something like this:
- (IBAction)buttonPressed:(UIButton *)sender {
[self navigateToMyNewViewController];
}
- (void)navigateToMyNewViewController {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"myNewStoryboard" bundle:nil];
MyNewViewController *myNewVC = (MyNewViewController *)[storyboard instantiateViewControllerWithIdentifier:#"MyNewViewController"];
[self.navigationController pushViewController:myNewVC animated:YES];
}
Navigation from MyNewViewController your can implement as you want. It may be segues.
MyNewViewController *myVC = [self.storyboard instantiateViewControllerWithIdentifier:#"YOUR_VC_NAME_HERE"];
This will instantiate your ViewController, from here you can present it like so
[self presentViewController:myVC animated:YES completion:nil]
The image shows where you set the storyboard name that you're referring to
Try This it's working for me ,
Use below line of code :
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main"bundle:nil];
LoginViewController *loginVC = (LoginViewController*)[storyboard instantiateViewControllerWithIdentifier:#"LoginViewController"];
[self.navigationController pushViewController:loginVC animated:YES];
We need to set storyboard id as per mention in below,
you can navigate one storyboard to another storybord:
first you import your viewcontroller class to appdelegate.h
AppDelegate *appDelegateTemp = [[UIApplication sharedApplication]delegate];
appDelegateTemp.window.rootViewController = [[UIStoryboard storyboardWithName:#"storyboard_name" bundle:[NSBundle mainBundle]] instantiateInitialViewController];
Like the way you use storyboard, use
MainViewController *mainVC = [[MainViewController alloc] initWithNibName:#"MainViewController" bundle:nil]
[self.navigationController pushViewController:mainVC animated:YES];

Loading new Storyboard and UIButton inactive

I added a new UIViewController to get a log in issue fixed and now the button in the NavigationBar on the next scene are inactive. Here is the code I used to load the new StoryBoard:
-(void)newSotrybooard{
UIStoryboard *settingsStoryboard = [UIStoryboard storyboardWithName:#"LogedIn" bundle:nil];
UIViewController *initialSettingsVC = [settingsStoryboard instantiateInitialViewController];
initialSettingsVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:initialSettingsVC animated:YES completion:NULL];
}
I added the new storyboard after I couldn't get the NavigationBar to show up and push without and error on the main storyboard. This is the only code that has changed. The Navigation Controller does not have a class associated with it and neither does the TableView to follow. I can also not scroll the Table view. Thank you for your help!
Update:
I updated the code above and
The error I receive is:
Warning: Attempt to present <UINavigationController: 0x109fa0ce0> on <PrivateViewController: 0x109f6ef80> whose view is not in the window hierarchy!
Based on the information you have provided, I surmise that the following could be helpful -
Yes, you have used instantiateViewControllerWithIdentifier.
But, remember it instantiates and returns the view controller with
the specified identifier. You're missing that.
Provide the same name to your new Storyboard in your code and
File Inspector (like you named it LogedIn above) and it
should be set in the Main Interface (Target >> General >> Main
Interface).
See rootViewController? The rootViewController
for the window needs to be assigned (either via Storyboard or
programmatically). Please check. I have added a UINavigationController in my example below -
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"StoryboardName" bundle:nil];
ViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"StoryboardName"];
vc.title = #"Is this title visible?";
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
self.window.rootViewController = nav;
return YES;
}
For the ViewController.m
-(void) goToSettings {
UIStoryboard *settingsStoryboard = [UIStoryboard storyboardWithName:#"SettingsStoryboard" bundle:nil];
UIViewController *initialSettingsVC = [settingsStoryboard instantiateInitialViewController];
initialSettingsVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:initialSettingsVC animated:YES completion:NULL];
}

Calling storyboard from UIViewcontroller

I don't know if this is possible or not but I wrote a project using xibs and want to modally switch to a storyboard project.
I know that to switch VC's you do something like
NewViewController *NewVC = [[NewViewController alloc] init];
[self presentModalViewController:NewVC animated:YES];
upon clicking a button, that I'll call "switch"
There is another project using solely storyboards that I want to call using "switch"
How do I go about doing this? Is it possible to do this?
Yes it is possible. You can do something like this:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"YourStoryboardName" bundle:nil];
MainMenuViewController *mainmenuvc = [storyboard instantiateViewControllerWithIdentifier:#"mainMenuViewController"];
[self.navigationController pushViewController:mainmenuvc animated:YES];
EDIT
If I understand your comment, you want to change the root view controller. You can do so by:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"RVCStoryboard" bundle:nil];
MainMenuViewController *mainmenuvc = [storyboard instantiateViewControllerWithIdentifier:#"mainMenuViewController"];
[[UIApplication sharedApplication].delegate].window.rootViewController = mainmenuvc;
Please note that for this to work, in your RVCStoryboard you have to select the viewcontroller you are trying to load, and assign a name to it so that the instantiateViewControllerWithIdentifier: method will work. Check the attached image, the field "Storyboard ID":

Resources