• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 尝试在 iPhone 上模态显示 UIImagePickerController 时崩溃

[复制链接]
菜鸟教程小白 发表于 2022-12-12 16:46:40 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

当我尝试从特定 View Controller 呈现 UIImagePickerController 时,我的应用程序崩溃了。

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

- (void)showImagePickerForSourceTypeUIImagePickerControllerSourceType)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 日编辑: self 是第二段中描述的 CLYImagePickerController。它只是一个 NSObject 子类。 CLYImagePickerControllerdelegate定义如下:

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

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


对于一个特定的 View Controller ,它恰好很大,因为它处理 UITableView 以及 UITextView 的许多方面,呈现 UIImagePickerControllerUIImagePickerControllerSourceTypePhotoLibrary 的 code> 几乎每次都会导致应用程序崩溃并出现 EXC_BAD_ACCESS 异常(在少数情况下,启动选择器时应用程序不会崩溃,但是在不对项目进行任何更改的情况下进行重建通常会扭转这种情况,并且应用程序将再次开始崩溃)。再次强调,这些崩溃只有在提供源类型为 UIImagePickerControllerSourceTypePhotoLibraryUIImagePickerController 时才会发生。 提供 源类型为 UIImagePickerControllerSourceTypeCamera 的 UIImagePickerController 可以正常启动。

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

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

奇怪的是,在测试 View 中启动具有照片库源类型的选取器后,问题 View Controller 能够呈现具有照片库源类型的选取器而没有任何问题。当我第一次呈现具有源类型 UIImagePickerControllerSourceTypePhotoLibraryUIImagePickerController 时,是否在全局范围内设置了某些内容,这允许我在有问题的 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) boundingRectWithSizeptions: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:ayer::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:ayer::layout_if_needed(CA::Transaction*) + 350
33 QuartzCore                     0x2f8b0ff9 CA:ayer::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:bserver_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)



Best Answer-推荐答案


这个怎么样:

- (void) showImagePickerForSourceTypeUIImagePickerControllerSourceType)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 respondsToSelectorselector(showImagePicker]) {
        //    [self.providerDelegate performSelectorOnMainThreadselector(showImagePicker
        //                                            withObject:imagePickerController
        //                                         waitUntilDone:NO];
        //}
    }
}

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

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap