Push View Controller, Black Screen

前端 未结 7 2334
旧时难觅i
旧时难觅i 2020-12-14 08:55

I\'m pushing to a new view controller and passing some data to it. When I run the application I can press the button and push to a new view but the screen is completely blac

相关标签:
7条回答
  • 2020-12-14 09:02

    Typically, you transition to another view controller by calling:

    initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    

    on your custom UIViewController.

    If you're not using a xib file, then what you're doing may be fine. Are you dynamically creating your UI elements within the constructor of your ImagesViewController?

    0 讨论(0)
  • 2020-12-14 09:08

    I was trying without using storyboard, and its just that the default screen it uses is in black color. I changed the background color to white and it worked.

    Pushed the controller this way-

    NextController *nextController = [[NextController alloc]init]; [self.navigationController pushViewController:nextController animated:YES];

    In NextController-

    (void)viewDidLoad{
    [self.view setBackgroundColor:[UIColor whiteColor]];
    

    }

    0 讨论(0)
  • 2020-12-14 09:12

    I got a good one:

    Make sure you are implementing the right Super class, delegate, etc.. in the top part of the viewController you are trying to present. i.e.

    I wasn't using/implementing UINavigationController at all

    class TMDetailBlogViewController: UINavigationController {
      //code goes here
    }
    

    After

    class TMDetailBlogViewController: UIViewController {
      //code goes here
    }
    
    0 讨论(0)
  • 2020-12-14 09:17

    When you're using a storyboard, and you want to push a view controller in code (rather than with a segue), you need to give the controller an identifier, and create it like this:

        ImagesViewController *ivc = [self.storyboard instantiateViewControllerWithIdentifier:@"MyIdentifier"];
        ivc.label = self.label.text;
        [self.navigationController pushViewController:ivc animated:YES];
    
    0 讨论(0)
  • 2020-12-14 09:18

    Xcode 7.3 and Swift 2.2

    In my case, I had made changes in the storyboard and made it a TabBarController and accordingly changed the class of the controller from UIViewController to UITabBarController. After some tweaking, this change wasn't favourable and I un did all the changes and got a black screen then because I had forgotten to change the class of the controller. I changed it back to UIViewController and it started working again.

    So check if you have made the same mistake. The black screen came because the storyboard had a class(UIView/UITabBar/UITableView Controller) but that wasnt the same in code.

    0 讨论(0)
  • 2020-12-14 09:25

    The view controller you are pushing is not having any frame dimension set.It is always recommended to call designated init for objects. For view controllers, designated init method is

    - (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle
    

    if you have a xib assign it like

    ImagesViewController *ivc = [[ImagesViewController alloc] initWithNibName:<your xib> bundle:[NSBundle mainbundle];
    

    if you are using custom view, assign a frame dimension and add it as subview

    0 讨论(0)
提交回复
热议问题