gpt4 book ai didi

ios - 尝试在 iPhone 上以模态方式呈现 UIImagePickerController 时崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:38:22 26 4
gpt4 key购买 nike

当我尝试显示 UIImagePickerController 时,我的应用程序崩溃了来自特定的 View Controller 。

我有一个对象,CLYImagePickerController ,处理 UIImagePickerController 的简单事情,例如创建、呈现和处理 UIAlertView为用户提供关于哪种 UIImagePickerController 的选项呈现和处理用户选择的图像。这个对象告诉委托(delegate) View Controller 呈现一个 UIImagePickerController使用以下方法:

- (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
imagePickerController.sourceType = sourceType;
imagePickerController.delegate = self;

[self.delegate presentViewController:imagePickerController animated:YES completion:nil];
}

编辑 2013 年 11 月 27 日: selfCLYImagePickerController在第二段中描述。它只是一个 NSObject 子类。 CLYImagePickerControllerdelegate定义如下:

@property (weak, nonatomic) UIViewController <CLYImagePickerControllerDelegate> *delegate;

CLYImagePickerController的目的是允许 View Controller (delegate)调用它在 View Controller 的 View 中显示一个操作表,在操作时可以调用一个 UIImagePickerController。其源类型由点击的操作表按钮确定。基本上,CLYImagePickerController处理一堆重复的代码,否则这些代码会使 delegate 变得困惑查看 Controller 的代码,并允许在使用图像选择器的整个应用程序中采用统一的呈现样式。


对于特定的 View Controller ,它恰好很大,因为它处理 UITableView 的许多方面。以及 UITextView , 呈现 UIImagePickerController来源类型 UIImagePickerControllerSourceTypePhotoLibrary导致应用程序崩溃并显示 EXC_BAD_ACCESS几乎每次都会出现异常(在极少数情况下,应用程序在启动选择器时不会崩溃,但在不对项目进行任何更改的情况下进行重建通常会逆转这种情况,应用程序将再次开始崩溃)。同样,我认为有必要强调这些崩溃仅在 UIImagePickerController 时发生。来源类型 UIImagePickerControllerSourceTypePhotoLibrary 呈现UIImagePickerController来源类型 UIImagePickerControllerSourceTypeCamera启动得很好。

我在帖子底部提供了其中一次崩溃的崩溃日志。

确保问题不是出在我的 CLYImagePickerController 上对象,我使用空 View Controller 对其进行了测试,该 View Controller 的唯一功能是充当 CLYImagePickerController 的委托(delegate).在这个 View 中,UIImagePickerController对于两种源类型,每次都能正常启动而不会失败。这让我相信有问题的 View Controller 代码中有一些东西以某种方式干扰了 UIImagePickerController。 ,但我不知道它可能是什么。有没有其他人有类似的问题谁可以阐明这个问题?

奇怪的是,在测试 View 中启动带有照片库源类型的选择器后,问题 View Controller 能够毫无问题地呈现带有照片库源类型的选择器。当我呈现 UIImagePickerController 时,是否在全局设置了某些内容?来源类型 UIImagePickerControllerSourceTypePhotoLibrary第一次允许我在有问题的 View Controller 中毫无问题地再次呈现它?

崩溃日志

以下是其中一次崩溃的堆栈跟踪示例。我真的不知道这一切意味着什么。在某处访问与字体相关的内容似乎存在某种问题?我不知道。

Thread 0: Crashed: com.apple.main-thread
0 CoreText 0x2db76d52 TComponentFont::GetRawBoundingBox() const + 13
1 CoreText 0x2db69bcf TBaseFont::CalculateFontMetrics(bool) const + 110
2 CoreText 0x2db69bcf TBaseFont::CalculateFontMetrics(bool) const + 110
3 CoreText 0x2db76d3f TComponentFont::CalculateFontMetrics(bool) const + 34
4 CoreText 0x2db69a15 TBaseFont::InitFontMetrics() const + 44
5 CoreText 0x2db69851 TBaseFont::GetStrikeMetrics(float, CGAffineTransform const*, bool) const + 104
6 CoreText 0x2db6961f TFont::InitStrikeMetrics() const + 38
7 CoreText 0x2db695cd CTFontGetAscent + 92
8 GraphicsServices 0x321122c5 GSFontEnsureExtraData + 228
9 GraphicsServices 0x321143dd GSFontGetLatin1LayoutInfo + 44
10 UIFoundation 0x34e0f49d -[UIFont(UIFont_AttributedStringDrawing) _getLatin1GlyphMapping:andAdvanceMapping:] + 12
11 UIFoundation 0x34de5be7 __NSStringDrawingEngine + 3814
12 UIFoundation 0x34deae4b -[NSAttributedString(NSExtendedStringDrawing) boundingRectWithSize:options:context:] + 902
13 UIKit 0x2ff24383 -[UILabel _updateScaledMetricsForRect:] + 594
14 UIKit 0x2fcc8b9f -[UILabel setAdjustsFontSizeToFitWidth:] + 206
15 PhotosUI 0x33d620df -[PUFlatWhiteInterfaceTheme configureAlbumListSubtitleLabel:]
16 PhotosUI 0x33cb82f5 +[PUAlbumListCellContentView _updateLabelGlobalCachedSizes]
17 libobjc.A.dylib 0x37803271 _class_initialize + 572
18 libobjc.A.dylib 0x3780a7cf lookUpImpOrForward + 130
19 libobjc.A.dylib 0x3780302b _class_lookupMethodAndLoadCache3 + 34
20 libobjc.A.dylib 0x37802df9 _objc_msgSend_uncached + 24
21 PhotosUI 0x33cb720d -[PUAlbumListTableViewController tableView:cellForRowAtIndexPath:]
22 UIKit 0x2fd61315 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 408
23 UIKit 0x2fd096cd -[UITableView _updateVisibleCellsNow:] + 1800
24 UIKit 0x2fd08ef1 -[UITableView layoutSubviews] + 184
25 UIKit 0x2fc2f353 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 346
26 QuartzCore 0x2f8b5943 -[CALayer layoutSublayers] + 142
27 QuartzCore 0x2f8b1167 CA::Layer::layout_if_needed(CA::Transaction*) + 350
28 UIKit 0x2fc44231 -[UIView(Hierarchy) layoutBelowIfNeeded] + 532
29 PhotosUI 0x33d7aca9 -[PUAbstractAlbumListViewController viewDidLayoutSubviews]
30 UIKit 0x2fc2f429 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 560
31 QuartzCore 0x2f8b5943 -[CALayer layoutSublayers] + 142
32 QuartzCore 0x2f8b1167 CA::Layer::layout_if_needed(CA::Transaction*) + 350
33 QuartzCore 0x2f8b0ff9 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
34 QuartzCore 0x2f8b0a0d CA::Context::commit_transaction(CA::Transaction*) + 228
35 QuartzCore 0x2f8b081f CA::Transaction::commit() + 314
36 QuartzCore 0x2f8aa54d CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 56
37 CoreFoundation 0x2d475f69 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
38 CoreFoundation 0x2d4738f7 __CFRunLoopDoObservers + 286
39 CoreFoundation 0x2d473c43 __CFRunLoopRun + 738
40 CoreFoundation 0x2d3de471 CFRunLoopRunSpecific + 524
41 CoreFoundation 0x2d3de253 CFRunLoopRunInMode + 106
42 GraphicsServices 0x321182eb GSEventRunModal + 138
43 UIKit 0x2fc93845 UIApplicationMain + 1136
44 Celly 0x0000cde3 main (main.m:17)

最佳答案

这个怎么样:

- (void) showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType
{
if ([UIImagePickerController isSourceTypeAvailable:sourceType])
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = sourceType;
imagePickerController.delegate = self;
[self.delegate presentModalViewController:imagePickerController animated:NO];
// if this doesn't work try using:
// if ([self.providerDelegate respondsToSelector:@selector(showImagePicker:)]) {
// [self.providerDelegate performSelectorOnMainThread:@selector(showImagePicker:)
// withObject:imagePickerController
// waitUntilDone:NO];
//}
}
}

关于ios - 尝试在 iPhone 上以模态方式呈现 UIImagePickerController 时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20223295/

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