ViewController appears black when it appears

Hi, Everything, that I am new to iOS development, and I am currently having a problem with something, I am trying to make a mod entry form if the user is not logged in.

I use NSUserDefaults to store an identifier, which I just check to see if it exists. If this is not the case, I would like the UIViewController to appear.

So far I have the following code in my UINavigationController, which is inside the UITabViewController, I am trying to make the UIViewController appear above the first UINavigationController (the one that is selected), at the time of animation, but there is only a black screen, even though The login screen has all the relevant text fields, etc. If I set this login screen as the initial view for loading, it will load normally.

This is the code that appears in the first UINavigationController view manager.

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; if (![prefs stringForKey:@"id"]){ LoginViewController *loginController = [[LoginViewController alloc] init]; [self presentModalViewController:loginController animated:YES]; } else { [self loadCoffeeUserOrders:[prefs stringForKey:@"id"]]; } 

the modal view is loading, but for now it just looks black, I tried to create a new login screen and the same thing: nothing but a black screen.

I hope that for someone there is enough information to understand what may be, I am very new to iOS development, so if I made some mistakes, it would be nice to know where I am wrong.

thanks

+7
source share
3 answers

So, the LoginViewController created here is another instance from the one you created in your storyboard. I think you want to trigger a download and presentation in a storyboard.

The easiest way is to create a segue in the storyboard from your first view controller to the login controller you created there. You can drag ctrl from one view controller to another and select β€œModal” as the type of segue. Then go to the inspector for this session and give it an identifier. Let's say you call it "segueToLogin".

Then, to execute this segue from your code, just do something like this:

  if (![prefs stringForKey:@"id"]){ [self performSegueWithIdentifier:@"segueToLogin" sender:self]; } 

Hope this helps.

EDIT

To simply answer your question, imagine the following:

You have a great idea for the application, so you take a piece of paper from your pad and you sketch this wonderful design. Then your colleagues come so that you discard a new blank sheet of paper and show them this instead. They will not be impressed.

The same thing happened here. You have configured the view controller in your storyboard with all of your views. But then, when it came time to show it, you pulled out a new completely empty controller and showed it to the user. Pulling and actuating the shogi instead, you end up loading the instance of the actual controller instance that you need.

Now in the sections you create those in the storyboard so that the user can navigate through the scripts. Sometimes these passages are directly tied to a button or something else. But in this case, you do not want the user to click a button or something to represent the vc input, so you do the segue yourself.

Hope this makes sense.

+7
source

I had a similar problem, but the resolution was not mentioned above. The problem arose in the current new controller file β€œ.m” of the controller (the one I am trying to press / modal). There is a method called loadView inside, and if you leave it there, Xcode will ignore the xib that you have in the storyboard, and expect you to lay out the view. Remove this function and instead it will see xib.

Too much time has passed for this stupid mistake, I hope this helps to save someone else sensibly.

+3
source
 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; LoginViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"]; [vc setModalPresentationStyle:UIModalPresentationFullScreen]; [self presentModalViewController:vc animated:YES]; 
0
source

All Articles