development

팝 오버가 여전히 보이는 동안 UIPopovercontroller dealloc에 ​​도달

big-blog 2020. 7. 29. 07:22
반응형

팝 오버가 여전히 보이는 동안 UIPopovercontroller dealloc에 ​​도달


나는 내 질문에 대한 답변을 찾았지만 도움이되지 않았다는 것을 확신합니다. 여기에 a UIImagePickerController안에 표시 해야하는 간단한 코드가 있습니다 UIPopoverController.

-(void)takePicture:(id)sender{
UIImagePickerController *picker=[[UIImagePickerController alloc] init];
picker.delegate=self;
picker.sourceType=UIImagePickerControllerSourceTypeCamera;
picker.allowsEditing=YES;
UIPopoverController *poc=[[UIPopoverController alloc] 
                            initWithContentViewController:picker];
[poc presentPopoverFromBarButtonItem:bbItem 
            permittedArrowDirections:UIPopoverArrowDirectionAny
                            animated:NO];
}

이제 처음에 [UIPopoveController dealloc]도달하는 동안에도 오류가 발생하고 프로그램이 충돌합니다. ARC에 따라 유지, 릴리스 또는 자동 릴리스를 수행하지 않습니다. UIPopoverControllersARC 혜택을 누릴 때 특별히 고려해야 사항이 있습니까?


UIPopoverControllers는 항상 인스턴스 변수에 있어야합니다. 강력한 속성을 만드는 것이 좋습니다.

최신 정보:

iOS 8부터는을 사용해야합니다 UIPopoverPresentationController. 그런 다음 프리젠 테이션 컨트롤러가 팝 오버를 관리하므로 팝 오버에 대한 참조를 유지할 필요가 없습니다.

코드 예제 (iPhone 및 iPad에서 모두 작동) :

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.allowsEditing = YES;
picker.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController* popoverPC = picker.popoverPresentationController;
popoverPC.barButtonItem = bbItem;
popoverPC.permittedArrowDirections = UIPopoverArrowDirectionAny;
[self presentViewController:picker animated:YES completion:nil];

함수가 종료되면 팝 오버 컨트롤러에 대한 다른 참조가 없으므로 너무 일찍 할당 해제됩니다.

대신 수업의 회원으로 추가해보십시오.


@ phix23이 응답 한 것을 추가하여 다음과 같이 * poc 속성을 만듭니다.

@property (nonatomic, retain) IBOutlet UIPopoverController *poc;

그런 다음 변경

UIPopoverController *poc = [[UIPopoverController alloc] 
                            initWithContentViewController:picker];

...에 대한

self.poc = [[UIPopoverController alloc] 
                            initWithContentViewController:picker];

참고 URL : https://stackoverflow.com/questions/8895071/uipopovercontroller-dealloc-reached-while-popover-is-still-visible

반응형