(viewConroller.view removeFromSuperview) Thread:1 EXC_BAD_ACCESS (Code=1, address = 0x6000000008)

前端 未结 2 1730
温柔的废话
温柔的废话 2021-01-26 13:20

(^.^) Hi sorry for my English is not good.

Hi I have the next issue I create 2 buttons the first one button create one view controller and add his view to other viewcont

2条回答
  •  醉梦人生
    2021-01-26 13:52

    It seems that vc is an iVar, so you should not send release in kill: method. So just remove the code line:

    [vc release];
    

    and add it to your dealloc method.


    Note, it's better to use the code like below for your create:

    if (vc == nil)
      vc = [[[VC alloc] initWithNibName:@"VC" bundle:[NSBundle mainBundle]] retain];
    [_VW addSubview:vc.view];
    

    Otherwise, when your vc is not nil, it'll lead a memory leak.

提交回复
热议问题