一条线一直在崩溃,我认为这可能与 CFDictionary 有关,但不确定。请帮忙

Posted

技术标签:

【中文标题】一条线一直在崩溃,我认为这可能与 CFDictionary 有关,但不确定。请帮忙【英文标题】:One line keeps crashing, I think it could be something to do with CFDictionary but not sure. Please help 【发布时间】:2010-11-08 05:18:57 【问题描述】:

我有一行代码一直崩溃

NSArray* address = [NSArray arrayWithArray:[[[access.filteredResults objectAtIndex:[indexPath row]] addressArray] objectAtIndex:0]];

我调试了一下,发现addressArray是罪魁祸首。

它在一个名为 ABContact 的类中定义(由 Developer Cookbook 的作者 Erica Sadun 创建)

@property (nonatomic, readonly) NSArray *addressArray;

实现文件有

- (NSArray *) addressArray return [self arrayForProperty:kABPersonAddressProperty];

我得到的错误信息是

-[__NSCFDictionary getObjects:range:]:无法识别的选择器发送到实例 0x18aeb0 *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFDictionary getObjects:range:]: unrecognized selector sent to instance 0x18aeb0” *** 第一次抛出调用堆栈: ( 0 核心基础 0x3284b987 __exceptionPreprocess + 114 1 libobjc.A.dylib 0x31aca49d objc_exception_throw + 24 2核心基础0x3284d133-[NSObject(NSObject)不识别选择器:]+102 3 核心基础 0x327f4aa9 ___转发___ + 508 4 核心基础 0x327f4860 _CF_forwarding_prep_0 + 48 5 核心基础 0x327dc325 -[NSArray initWithArray:range:copyItems:] + 372 6 核心基础 0x327e94d3 +[NSArray arrayWithArray:] + 62 7 ContactMapper 0x00003c17 -[RootViewController tableView:cellForRowAtIndexPath:] + 1110 8 UIKit 0x32c46a21-[UITableView(UITableViewInternal)_createPreparedCellForGlobalRow:withIndexPath:] + 516 9 UIKit 0x32c467f3-[UITableView(UITableViewInternal)_createPreparedCellForGlobalRow:] + 34 10 UIKit 0x32c44d2d-[UITableView(_UITableViewPrivate)_updateVisibleCellsNow:] + 936 11 UIKit 0x32c43edd-[UITableView layoutSubviews] + 140 12 UIKit 0x32bf00cf -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 26 13 CoreFoundation 0x327e9bbf -[NSObject(NSObject) performSelector:withObject:] + 22 14 QuartzCore 0x3087b685 -[CALayer layoutSublayers] + 120 15 石英核心 0x3087b43d CALayerLayoutIfNeeded + 184 16 QuartzCore 0x3089e593 -[CALayer(CALayerPrivate) layoutBelowIfNeeded] + 18 17 UIKit 0x32c1c3f3 -[UIView(层次结构)layoutBelowIfNeeded] + 22 18 UIKit 0x32e41cb3-[UISplitViewController willRotateToInterfaceOrientation:duration:] + 614 19 UIKit 0x32cadc71-[UIViewController 窗口:willRotateToInterfaceOrientation:持续时间:] + 540 20 UIKit 0x32ced6b3-[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 1158 21 UIKit 0x32caef5f -[UIWindow _setRotatableViewOrientation:duration:force:] + 54 22 UIKit 0x32c27007-[UIWindow _updateToInterfaceOrientation:duration:force:] + 74 23 UIKit 0x32c26f81-[UIWindow _updateInterfaceOrientationFromDeviceOrientation:] + 112 24 UIKit 0x32c26ead-[UIWindow_handleDeviceOrientationChange:] + 88 25 基础 0x320f1623 _nsnote_callback + 142 26 核心基础 0x327d2123 __CFXNotificationPost_old + 402 27 核心基础 0x327d1dc3 _CFXNotificationPostNotification + 118 28 基础 0x320e0d23 -[NSNotificationCenter postNotificationName:object:userInfo:] + 70 29 UIKit 0x32bf0819-[UIDevice 设置方向:动画:] + 144 30 UIKit 0x32c152ff-[UIApplication_runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 438 31 UIKit 0x32be148b -[UIApplication 句柄事件:withNewEvent:] + 1114 32 UIKit 0x32be0ec9 -[UIApplication 发送事件:] + 44 33 UIKit 0x32be0907 _UIApplicationHandleEvent + 5090 34 图形服务 0x3094af03 PurpleEventCallback + 666 35 核心基础 0x327e06ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26 36 核心基础 0x327e06c3 __CFRunLoopDoSource1 + 166 37 核心基础 0x327d2f7d __CFRunLoopRun + 520 38 核心基础 0x327d2c87 CFRunLoopRunSpecific + 230 39 核心基础 0x327d2b8f CFRunLoopRunInMode + 58 40 UIKit 0x32c14309-[UIApplication_run] + 380 41 UIKit 0x32c11e93 UIApplicationMain + 670 42 联系人映射器 0x00002b67 主要 + 70 43 ContactMapper 0x00002b1c 开始 + 40

不知道怎么解决?

access.filteredResults 是一个 NSArray

这可能是 AddressBook 数据的处理方式(CFDictionary vs NSArray 或 NSDictionary)。我已经花了 15 个小时,我被困住了。任何帮助将不胜感激。

【问题讨论】:

【参考方案1】:

不。 NSCFDictionary 与您的问题无关。

您的问题是您保留不足或过度释放了一个数组对象,该对象死亡,另一个对象(在这种情况下,它是一个字典,但它可能是任何东西)同时被分配地址。您的代码正在尝试使用旧对象创建一个数组,但最终却传递了继承它的字典。

您需要找出您在哪里过度释放或未能保留addressArray 的值。

在 Zombies 工具下运行您的应用程序可能会有所帮助,其目的是调试过早释放或无法保留对象的应用程序。

【讨论】:

以上是关于一条线一直在崩溃,我认为这可能与 CFDictionary 有关,但不确定。请帮忙的主要内容,如果未能解决你的问题,请参考以下文章

一条线的分段节点问题第二次测试

如何判断一条线是否与C#中的多边形相交?

cad三维制图中如何找到一条线与一个面的交点,如空间斜线与水平标高24M面的交点,如何找到该交点

openGL着色器:两个对象和一条线来连接它们

如何在matlab中以方位角画一条线?

UIButton:在文本下方以 x pts 间距画一条线?