ARC seems to be releasing the view of my NSViewController

后端 未结 2 1067
借酒劲吻你
借酒劲吻你 2021-01-28 06:11

I am trying to solve a larger problem and I am tipping on the fact that ARC apparently is releasing the view to my NSViewController too early. I think :) So I created a simple a

2条回答
  •  一生所求
    2021-01-28 07:02

    Add a property to hold the view controller. Your controller currently has nothing to keep it alive past the end of the method that allocates it.

    Add:

    @property (strong) TestViewController *tvc;
    

    Modify:

    self.tvc =  [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:nil];
    

    (I'm curious...what do you see as the point of creating a view controller if all you want is the view it contains?)


    Concerning the general approach, it seems that this is more properly behavior that should be implemented using a container view controller. That mechanism allows multiple view controllers to share the screen in an organized way.

提交回复
热议问题