推送视图控制器,黑屏 [英] Push View Controller, Black Screen

查看:17
本文介绍了推送视图控制器,黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在推送到一个新的视图控制器并将一些数据传递给它.当我运行应用程序时,我可以按下按钮并推到一个新视图,但屏幕是全黑的.任何帮助表示赞赏.

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 black. Any help is appreciated.

- (IBAction)button:(id)sender {

    NSString *firstField = self.field.text;
    NSString *secondField = self.field2.text;

    self.resultsArray = [[NSArray alloc] initWithObjects:firstField, secondField, nil];

    NSUInteger randomResult = arc4random_uniform(self.resultsArray.count);
    self.label.text = [self.resultsArray objectAtIndex:randomResult];

    ImagesViewController *ivc = [[ImagesViewController alloc] init];
    ivc.label = self.label.text;
    [self.navigationController pushViewController:ivc animated:YES];

}

推荐答案

当你使用故事板,并且你想在代码中推送一个视图控制器(而不是一个 segue),你需要给控制器一个标识符,并像这样创建它:

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];

这篇关于推送视图控制器,黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆