UIView missing background

My application's structure looks like:

  • UIViewController1

     - UIViewController2
    
               - Add UIView programmatically
    
  • UIViewController1 contains UIViewController2, and I add some UIView, loading from Xib, to the UIViewController2 with the following code:

    SessionView* b = [[[NSBundle mainBundle] loadNibNamed:@"SessionView" owner:self options:nil] lastObject];
    [self.view addSubview:b];
    
    //- set Frame before or after addSubView, there is no difference
    CGRect frame = b.frame;
    frame.origin.x = 0;
    frame.origin.y = 0;
    b.frame = frame;
    
    

    The original UIView looks like this:

    原始UIView

    After adding to the UIViewController, it looks like this:

    添加后

    With the following code, when I assign the width and height of the UIView equal to a part of the width and height of the main view, it looks good

    
    SessionView* b = [[[NSBundle mainBundle] loadNibNamed:@"SessionView" owner:self options:nil] lastObject];
    
        [self.view addSubview:b];
        CGRect frame = b.frame;
        frame.origin.x = 0;
        frame.origin.y = 0;
    
        //------- Assign the Width and Height Value
        //-------------------------------------------
        frame.size.width = CGRectGetWidth(self.view.bounds) / 3;
        frame.size.height = CGRectGetHeight(self.view.bounds) / 3;
    
        b.frame = frame;
    

    接受


    看来要添加viewController直接作为子视图,而不是你应该添加viewviewController作为子视图。

    SessionView* b = [[[NSBundle mainBundle] loadNibNamed:@"SessionView" owner:self options:nil] lastObject];
    [self.view addSubview:b.view];
    
    链接地址: http://www.djcxy.com/p/74276.html

    上一篇: 投射细胞类型出列的问题

    下一篇: UIView缺少背景