当我尝试从特定 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 子类。 CLYImagePickerController
的delegate
定义如下:
@property (weak, nonatomic) UIViewController <CLYImagePickerControllerDelegate> *delegate;
CLYImagePickerController
的目的是允许 View Controller (delegate
)调用它以在 View Controller 的 View 中显示操作表,当执行时on 可以调用 UIImagePickerController
,其源类型由被点击的操作表按钮确定。基本上,CLYImagePickerController
处理一堆重复的代码,否则这些代码会使 delegate
View Controller 的代码变得困惑,并允许在使用图像选择器的整个应用程序中实现统一的呈现风格。
对于一个特定的 View Controller ,它恰好很大,因为它处理 UITableView
以及 UITextView
的许多方面,呈现 UIImagePickerController源类型
UIImagePickerControllerSourceTypePhotoLibrary
的 code> 几乎每次都会导致应用程序崩溃并出现 EXC_BAD_ACCESS
异常(在少数情况下,启动选择器时应用程序不会崩溃,但是在不对项目进行任何更改的情况下进行重建通常会扭转这种情况,并且应用程序将再次开始崩溃)。再次强调,这些崩溃只有在提供源类型为 UIImagePickerControllerSourceTypePhotoLibrary
的 UIImagePickerController
时才会发生。 提供 源类型为
可以正常启动。UIImagePickerControllerSourceTypeCamera
的 UIImagePickerController
我在帖子底部提供了其中一次崩溃的崩溃日志。
为了确保问题不在于我的 CLYImagePickerController
对象,我使用空 View Controller 对其进行了测试,该 Controller 的唯一功能是充当 CLYImagePickerController
的委托(delegate).在此 View 中,UIImagePickerController
对于两种源类型每次都正确启动而不会失败。这让我相信有问题的 View Controller 的代码中有一些东西以某种方式干扰了 UIImagePickerController
,但我不知道它可能是什么。有没有其他人遇到过类似的问题,可以对这个问题有所了解吗?
奇怪的是,在测试 View 中启动具有照片库源类型的选取器后,问题 View Controller 能够呈现具有照片库源类型的选取器而没有任何问题。当我第一次呈现具有源类型 UIImagePickerControllerSourceTypePhotoLibrary
的 UIImagePickerController
时,是否在全局范围内设置了某些内容,这允许我在有问题的 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)
这个怎么样:
- (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/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |