简体   繁体   English

在ViewController中看不到情节提要

[英]can't see storyboard in viewcontroller

connect storyboard with ResultViewController 将故事板与ResultViewController连接

I have set my storyboard's className as ResultViewController, on it there're some labels and buttons 我将故事板的className设置为ResultViewController,上面有一些标签和按钮

following is it's code, also add another label 以下是它的代码,还添加了另一个标签

(void)didReceiveMemoryWarning {
   [super didReceiveMemoryWarning];
   // Dispose of any resources that can be recreated.   }


(void)viewDidLoad {
    [super viewDidLoad];
    [self.view setFrame:CGRectMake(0, 0, 600, 900)];
     UILabel* chanceLB =[[UILabel alloc]initWithFrame:CGRectMake(10, 100, 50, 50)];
     chanceLB.text=@"lalala";
    [self.view addSubview:chanceLB];
    self.view.backgroundColor=[UIColor redColor];
    NSLog(@"this is result view");

} }

add this ResultViewControllre: 添加此ResultViewControllre:

dispatch_async(dispatch_get_main_queue(), ^{
            ResultViewController *resultView=[[ResultViewController alloc]init];
            [self presentViewController:resultView animated:YES completion:nil];

            NSLog(@"count:%lu ",(unsigned long)[[self.view subviews] count]);
        });

but i can't see any element on storyboard in the view, only see a "lalala" label and red background, what's more in console, it prints 21, I don't understand why there are 21 subviews since i have only add this resultView on self.view 但是我在视图中的故事板上看不到任何元素,只看到了“拉拉”标签和红色背景,在控制台中更是如此,它显示了21个,我不明白为什么有21个子视图,因为我只添加了这个self.view上的resultView

It looks like you're having some constraint issues on your storyboard. 看来您的故事板上有一些约束问题。 Have you added any constraints to the elements on your storyboard? 您是否对情节提要上的元素添加了任何约束? Try this: 尝试这个:

  • Select an element on your storyboard (Looks like you have a UIButton you could select). 在情节提要板上选择一个元素(看起来像有一个UIButton可以选择)。

  • Go to editor > align > horizontally in container 转到编辑器>对齐>在容器中水平

  • Go to editor > align > vertically in container 转到编辑器>对齐>在容器中垂直

This should center your element in the view. 这应该使元素在视图中居中。 If this worked then that means that you haven't set any constraints to the elements and are not viewable within the view controller of your storyboard. 如果这可行,则意味着您尚未对元素设置任何约束,并且无法在情节提要的视图控制器中查看。

For more please read this tutorial: 有关更多信息,请阅读本教程:

http://www.raywenderlich.com/115440/auto-layout-tutorial-in-ios-9-part-1-getting-started-2][1] http://www.raywenderlich.com/115440/auto-layout-tutorial-in-ios-9-part-1-getting-started-2][1]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM