gpt4 book ai didi

iOS 崩溃 : Terminating app due to uncaught exception reason: UIPopoverPresentationController should have a non-nil sourceView

转载 作者:行者123 更新时间:2023-11-29 12:26:26 26 4
gpt4 key购买 nike

我需要帮助解决这次崩溃。我检查了 stackoverflow 的答案,但没有一个答案与我的情况有关。这是我的代码。

  - (void)addImagesActionSheetClickedButtonAtIndex:(NSInteger)buttonIndex
{
// Cancel
if (buttonIndex == 2) return;

//Take picture
if (buttonIndex == 0)
{
//Take picture
isFromLibrary = NO;
[self.imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self.navigationController presentViewController:self.imagePicker animated:YES completion:NULL];
return;
}

// Library picture
if (buttonIndex == 1)
{

if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeSavedPhotosAlbum]) return;

UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:self.imagePicker];
[popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4, 0, 0)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}

如果我单击按钮索引 1 并关闭 UIPopoverController,然后单击按钮索引 0 拍照,我的应用程序崩溃了。

这是我的崩溃报告

'Terminating app due to uncaught exception 'NSGenericException', reason: 'UIPopoverPresentationController () should have a non-nil sourceView or barButtonItem set before the presentation occurs.

如有任何建议或提示,我们将不胜感激。如果我需要发布更多代码,请告诉我。

最佳答案

注意文档中的讨论:

源代码

Use this property in conjunction with the sourceView property to specify the anchor location for the popover. Alternatively, you may specify the anchor location for the popover using the barButtonItem property.

非常简洁明了。只需添加一个 sourceView 引用

https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIPopoverPresentationController_class/index.html#//apple_ref/occ/instp/UIPopoverPresentationController/sourceRect

关于iOS 崩溃 : Terminating app due to uncaught exception reason: UIPopoverPresentationController should have a non-nil sourceView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28977348/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com