버튼을 터치했을 때 하위보기를 생성하려는 기본보기가있는 앱에서 작업하고 있습니다. 따라서 button 이벤트를 받으면 MainViewController는 initWithNibName을 호출하고 ChildViewController를 ivar에 저장하여 자식 뷰를 생성합니다. 그런 다음 애니메이션을 첨부하고 childVC.view.hidden = NO로 설정하여 ChildView를 표시합니다.왜 initWithNibName을 사용할 때 UIViewController가 여분의 시간을 유지합니까?
이 작동하지만 ChildView를 닫은 후에 ChildViewController가 해제되지 않은 것으로 나타났습니다. ChildVC의 보유 횟수가 처음으로 하위보기에 액세스 할 때 1에서 2로 바뀌 었음을 알았습니다. 그래서 박테리아를로드하는 용기에 무언가는 ChildVC를 다시 유지하는 것으로 보입니다 (객체 초기화 중에 예상되는 초기 보유 외에도).
누군가 내가 ChildVC가 여분의 시간을 유지하는 이유를 알아낼 수 있습니까? 어떻게하면 하위 뷰를 닫을 때 완전히 릴리스되는지 확인할 수 있습니까?
편집 : 여기 약간의 코드가 있지만 약간만 간략화되었습니다. 부모 뷰 컨트롤러의 메소드입니다. 코드없이
-(IBAction)onLaunchChildButtonTouched:(id)sender
{
m_childViewController = [[ChildViewController alloc] initWithNibName:@"ChildViewController" bundle:nil];
[m_childViewController setParentDelegate:self]; // this is a weak reference
// m_childViewController retain count here is 1, as expected
m_childViewController.view.hidden = YES;
// m_childViewController retain count is now 2, not expected
[self.view addSubview:m_childViewController.view];
[self addTransitionEntrDir:YES]; // code omitted
m_childViewController.view.hidden = NO;
}
-(void)onChildWantsToClose:(id)child
{
NSAssert(child == m_childViewController, @"unexpected childVC");
// if child view is now hidden, we should remove it.
if(m_childViewController != nil && m_childViewController.view.hidden)
{
[m_childViewController.view removeFromSuperview];
[m_childViewController release]; m_childViewController = nil;
// BUG: m_childViewController retain count is still 1 here, so it never gets released
}
}
은 실제 코드를 표시 할 수 있습니까? – Vladimir
일부 코드를 표시하면 A를이 Q로 가져 오는 데 도움이됩니다. – chown
일부 코드가있는 원본 게시물이 업데이트되었습니다. – gga80