可能重复:
UIPopovercontroller dealloc reached while popover is still visible
我正在创建一个通用应用程序并尝试从相机胶卷中选择一个图像。在iPhone上运行良好,iPad需要弹出,所以已经完成了,现在不断出现错误
-[UIPopoverController dealloc] reached while popover is still visible.
我研究过:
和谷歌,没有解决这个问题
现在,任何建议都表示赞赏
我已经在.h
中实现了popover委托的.m
- (void)logoButtonPressed:(id)sender /////////////iPad requires seperate method ////////////////
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
LogCmd();
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
////////
imagePicker.modalPresentationStyle = UIModalPresentationCurrentContext;
////////
[self presentModalViewController:imagePicker animated:YES];
}
else
{
// We are using an iPad
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
UIPopoverController *popoverController=[[UIPopoverController alloc] initWithContentViewController:imagePickerController];
popoverController.delegate=self;
[popoverController presentPopoverFromRect:((UIButton *)sender).bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
我现在也试过这个:
·H
@property (strong) UIPopoverController *pop;
的.m
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { ///code added
LogCmd();
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
[self presentModalViewController:imagePicker animated:YES];
///code added////////////////////////////
}
else {
if (self.pop) {
[self.pop dismissPopoverAnimated:YES];
}
// If usingiPad
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
UIPopoverController *popoverController=[[UIPopoverController alloc] initWithContentViewController:imagePickerController];
[popoverController presentPopoverFromRect:((UIButton *)sender).bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
答案 0 :(得分:8)
您实例化弹出窗口并将其分配给本地变量:
UIPopoverController *popoverController=[[UIPopoverController alloc] initWithContentViewController:imagePickerController];
一旦方法返回,变量就会超出范围,并且对象被释放,因为它不再拥有所有者。
您应该做的是声明一个strong
属性来分配弹出窗口。您已使用pop
属性完成此操作。因此,现在您需要做的就是在分配弹出窗口时将其分配给您的属性。这使您成为对象的所有者,因此不会取消分配。
self.pop = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
[self.pop presentPopoverFromRect:((UIButton *)sender).bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
希望这有帮助!