UIView not cover UIWindow - ios

I'm using MFSideMenu which instantiated in AppDelegate, if I call
`CMainViewController *vMain = [[UIStoryboard storyboardWithName:#"Main" bundle:NULL] instantiateViewControllerWithIdentifier:#"CMainView"];
[navigationController pushViewController:vMain animated:YES];`
It works fine, if I not do a call (automatically view created) and inside this view do a call - I have the issue.
Any ideas - thanks in advance!
Find the place:
If I call pushViewController inside UIAlertView - I get the issue, if outside it works.
[[WashappService sharedInstance] auth:^(BOOL value) {
if(value==TRUE){
[self presentViewController:[LoginController authConfirmScreen:self toUser:user toPhone:szPhone success:^{
[(MenuClientController*)self.menuContainerViewController.leftMenuViewController updateData];
User* user = [User new];
user = [UserPreference get:KEY_CLIENT];
user.typeOwner = self.isWashAdmin;
[UserPreference save:KEY_CLIENT toValue:user];
[[WashappService sharedInstance] updateToken:user.token];
if (self.isWashAdmin){
OOrdersViewController *vMain = [[UIStoryboard storyboardWithName:#"Main" bundle:NULL] instantiateViewControllerWithIdentifier:#"OOrdersViewController"];
[self.navigationController pushViewController:vMain animated:YES];
}else{
CMainViewController *vMain = [[UIStoryboard storyboardWithName:#"Main" bundle:NULL] instantiateViewControllerWithIdentifier:#"CMainView"];
// vMain.modalPresentationStyle = UIModalPresentationFullScreen;
[self.navigationController pushViewController:vMain animated:YES];
}
}] animated:YES completion:nil];
}

Related

Push view controller not working

I'm using UINavigation and UIPageView controller in a UIViewController. I have 3 buttons and here is my code :
- (IBAction)StartButtonClicked:(id)sender {
NSLog(#"start button pressed");
[_Timer invalidate];
_Timer = nil;
dispatch_async(dispatch_get_main_queue(), ^{
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
CardViewController* controller = [storyboard instantiateViewControllerWithIdentifier:#"CardViewController"];
[self.navigationController pushViewController:controller animated:NO];
}
}
- (void)pageViewController {
self.pvc = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pvc.view.frame = self.view.bounds;
[self.view addSubview:self.pvc.view];
[self.pvc setViewControllers:#[[viewControllerArray1 objectAtIndex:0]] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
}
- (IBAction)rightButtonPressed:(id)sender {
[self pageViewController];
[self.pvc setViewControllers:#[[viewControllerArray1 objectAtIndex:1]] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
}
- (IBAction)leftButtonPressed:(id)sender {
[self pageViewController];
[self.pvc setViewControllers:#[[viewControllerArray1 objectAtIndex:2]] direction:UIPageViewControllerNavigationDirectionReverse animated:YES completion:nil];
}
When I click on right button and came back to this view controller my start button's push view not working.
Please check the answer .
iOS - Push viewController from code and storyboard
Don't initialize Storyboard always,
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
You can set the rootViewController from the UtoryBoard itself.
Set initialViewController as a UINavigationController and Set the FirstViewController as RootViewController.
Edit :
For Push use the below code,
CardViewController* controller = [storyboard instantiateViewControllerWithIdentifier:#"CardViewController"];
[self.navigationController pushViewController:controller animated:NO];
and Back. If use the default backButton not need to write any code.
If use are using custom backButton,
[self.navigationController popViewController];
Check 2 things,
Your storyboard identifier is correct.
The root view have navigation Controller.
Your StoryBoard should be like this,

Black screen after button click

I'm quite new to Objective-C. I want to go to another view controller but it shows me only the black screen after the button click. Is there something that I'm missing here?
Here is my code:
- (IBAction)measuring1stscan:(id)sender {
measuringscan *second = [[measuringscan alloc]initWithNibName:nil bundle:nil];
[self presentViewController:second animated:NO completion:NULL];
}
*measuringscan is the name for another view controller
viewConreoller default is no color, it is black. just add second.view.backgroundColor = [UIColor redColor];
- (IBAction)measuring1stscan:(id)sender {
measuringscan *second = [[measuringscan alloc] init];
second.view.backgroundColor = [UIColor redColor];
[self presentViewController:second animated:NO completion:NULL];
}
#rose is right try to give different color and then check.
Still you face same issue then try to run below code.
Embadded viewcontroller into navigation controller and give unique identifier to second viewcontroller.
- (IBAction)measuring1stscan:(id)sender
{
UIStoryboard *st = [UIStoryboard storyboardWithName:[NSString stringWithFormat:#"StoryboardWithName"] bundle:NULL];
measuringscan *second = [st instantiateViewControllerWithIdentifier:#"viewcontrollerIdentifier"];
[self.navigationController pushViewController:second animated:YES];
}
If you are using storyboard then use following
measuringscan *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"StoryboardIdentifier"];
[self presentViewController:controller animated:YES completion:nil];
or
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:[NSString stringWithFormat:#"StoryboardName"] bundle:nil];
measuringscan *controller = [storyboard instantiateViewControllerWithIdentifier:#"viewcontroller'sIdentifier"];
[self presentViewController:controller animated:YES completion:nil];
And if you aren't using storyboard instead you are using xib's then use following
measuringscan *controller = [[measuringscan alloc] initWithNibName:nil bundle:nil];
[self presentViewController:controller animated:YES completion:nil];
Points to remember (as said by #rmaddy)
Class name should be start with capital letter
Variable name should start with small letter
It is the naming convention that should be followed by a developer.
For more details click here

Game Center: Matchmaking

In my card playing game I am trying to create a match, which, for a part, works;
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match {
self.match = match;
match.delegate = self;
if (!_matchStarted && match.expectedPlayerCount == 0) {
NSLog(#"Ready to start match!");
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:#"GameVC"];
vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[viewController presentViewController:vc animated:YES completion:nil];
//[viewController dismissViewControllerAnimated:YES completion:nil];
}
}
After a match is created successfully I want the GKMatchmakerViewController to be dismissed and I want the "vc" UIViewController to be shown. In the above example this is accomplished, but the GKMatchmakerViewController does not get dismissed.
If I remove the comment quotes it will be loaded after it got dismissed somehow and if I place the line above the presentViewController line I get an error stating that I am trying to present a view controller on a view controller that is not in the view hierarchy.
How do I dismiss the GKMVC and show the "vc" at the "same" time?
Thanks!
You need to dismiss the GKMatchMakerViewController, then use your current view controller to present the new modal:
if (!_matchStarted && match.expectedPlayerCount == 0) {
NSLog(#"Ready to start match!");
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:#"GameVC"];
vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[viewController dismissViewControllerAnimated:YES completion:nil];
[self presentViewController:vc animated:YES completion:nil];
}
Edit: A trick to get the current root view controller is [[UIApplication sharedApplication] delegate].window.rootViewController. So you should be able to present your modal with this:
[[[UIApplication sharedApplication] delegate].window.rootViewController presentViewController:vc animated:YES completion:nil];

How to make a Method display a new ViewController?

How can I make a Method display a new ViewController? I am trying to make the
Currently what I have :
-(void)gameOver{
[groundMovement invalidate];
[guyMovement invalidate];
topGround.hidden = YES;
bottomGround.hidden = YES;
guy.hidden = YES;
scoreLabel.hidden = YES;
gameViewController *viewController = [[UIStoryboard storyboardWithName:#"gameOver" bundle:nil] instantiateViewControllerWithIdentifier:#"gameOverViewController"];
[self presentViewController:viewController animated:YES completion:nil];
if (score > highScore) {
[[NSUserDefaults standardUserDefaults] setInteger:score forKey:#"HighScoreSaved"];
}
}
-(void)terminate{
MyNewViewController *myNewVC = [[MyNewViewController alloc] init];
// do any setup you need for myNewVC
[self presentModalViewController:myNewVC animated:YES];
}
Since your are using storyboards in your project, first make sure that your view controllers have a storyboard identifier. You can set it through the identity inspector in xCode. Then, you can instantiate a new view controller by calling:
YourViewControllerClass *viewController = [[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:#"ViewControllerId"]; // Replace "MainStoryboard" and "ViewControllerId" with your storyboard name and the storyboard id for your view controller respectively
Then, depending on how your needs you can either push the new view controller (if for example you're using a navigation controller):
[self.navigationController pushViewController:viewController animated:YES];
or present it modally
[self presentViewController:viewController animated:YES completion:nil];

presentViewController black screen or thread debug in IDE

I have seen the abundance of threads on this issue - I have tried all those solutions and they have failed. The build that ran, when I click the button it goes to the thread debugger page and I have no clue as to whats going on.
I need to go from a new class with its own .xib to the MainStoryboard where FirstViewController is.
- (IBAction)backToHome:(id)sender {
/*
FirstViewController *fvc = [[FirstViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:fvc animated:YES completion:nil];
*/
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
FirstViewController *fvc = [storyboard instantiateViewControllerWithIdentifier:#"FirstViewController"];
[self presentViewController:fvc animated:YES completion:nil];
}
When using the commented code it goes to a black screen
FirstViewController *fvc = [[FirstViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:fvc animated:YES completion:nil];
Here initWithNibName:nil causes black screen as it is not able to load nib.
i think you should add name
FirstViewController *fvc = [[FirstViewController alloc] initWithNibName:#"somethinghere" bundle:nil]; [self presentViewController:fvc animated:YES completion:nil];

Resources