search

Home  >  Q&A  >  body text

objective-c - addSubView 添加一个tableView,不能正常滚动

代码:

- (void)viewDidLoad
{
  [super viewDidLoad];
    // Do any additional setup after loading the view.
  groupViewController = [GroupViewController groupTableViewControllerWithDataSource:[GroupDataSource instance]
                                                                              Delegate:self];

  [self addChildViewController:groupViewController];
  [_groupView addSubview:groupViewController.view];
}

症状:
成功添加并显示,但tableView 无法滚动到底。怀疑是布局的问题,求教。

迷茫迷茫2768 days ago334

reply all(1)I'll reply

  • 天蓬老师

    天蓬老师2017-04-22 09:01:40

    You need to reset the frame here

    - (void)addChild:(UIViewController *)childToAdd withChildToRemove:(UIViewController *)childToRemove
    {
        assert(childToAdd != nil);
    
        if (childToRemove != nil)
        {
            [childToRemove.view removeFromSuperview];
        }
        CGRect frame = childToAdd.view.frame;
        frame.size.height = CGRectGetHeight(self.placeHoderView.frame);
        frame.size.width = CGRectGetWidth(self.placeHoderView.frame);
        childToAdd.view.frame = frame;
        self.currentVC = childToAdd;
        [self.placeHoderView addSubview:childToAdd.view];
    }
    

    reply
    0
  • Cancelreply