plot2.graphPoints = graphPointsMutableArray;
// plot2.graphPoints = @[LMGraphPointMake(CGPointMake(1, 25), @"1", @"34.5")];
如果我直接将plot2.graphPoints分配给一个NSArray,则它像第2行中那样工作正常,但是如果我像上面所示的第一个那样给它分配一个NSMutableArray,则应用程序会给我SIGABRT
,但以下情况除外如下所示
2018-12-04 02:53:18.079192+0500 ****[10946:258059] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSSingleObjectArrayI point]: unrecognized selector sent to instance 0x60400001f8a0'
*** First throw call stack:
(
0 CoreFoundation 0x000000011020c1cb __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010f720f41 objc_exception_throw + 48
2 CoreFoundation 0x000000011028c914 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000011018f178 ___forwarding___ + 1432
4 CoreFoundation 0x000000011018eb58 _CF_forwarding_prep_0 + 120
5 Fandex 0x000000010e144823 -[LMLineGraphView drawPlots] + 1939
6 Fandex 0x000000010e13d678 -[LMLineGraphView drawRect:] + 312
7 UIKit 0x0000000111f75c49 -[UIView(CALayerDelegate) drawLayer:inContext:] + 487
8 QuartzCore 0x0000000111b380d8 -[CALayer drawInContext:] + 267
9 QuartzCore 0x0000000111a4b6cf CABackingStoreUpdate_ + 254
10 QuartzCore 0x0000000111b3e1dd ___ZN2CA5Layer8display_Ev_block_invoke + 44
11 QuartzCore 0x0000000111b37b34 -[CALayer _display] + 1701
12 QuartzCore 0x0000000111ac521f _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 655
13 QuartzCore 0x0000000111af0a14 _ZN2CA11Transaction6commitEv + 500
14 QuartzCore 0x0000000111af1760 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 76
15 CoreFoundation 0x00000001101aedb7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
16 CoreFoundation 0x00000001101aed0e __CFRunLoopDoObservers + 430
17 CoreFoundation 0x0000000110193324 __CFRunLoopRun + 1572
18 CoreFoundation 0x0000000110192a89 CFRunLoopRunSpecific + 409
19 GraphicsServices 0x0000000116ef29c6 GSEventRunModal + 62
20 UIKit 0x0000000111ea523c UIApplicationMain + 159
21 Fandex 0x000000010e1c7aff main + 111
22 libdyld.dylib 0x0000000115336d81 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
这就是我在NSMutableArray
中添加对象的方式
NSMutableArray *graphPointsMutableArray = [[NSMutableArray alloc] init];
[graphPointsMutableArray addObject:@[LMGraphPointMake(CGPointMake(1, 25), @"1", @"34.5")]];
答案 0 :(得分:3)
您的两行不相等。
此:
plot2.graphPoints = @[LMGraphPointMake(CGPointMake(1, 25), @"1", @"34.5")];
将包含单个NSArray
的{{1}}分配给LMGraphPoint
与此同时:
plot2.graphPoints
将包含一个[graphPointsMutableArray addObject:@[LMGraphPointMake(CGPointMake(1, 25), @"1", @"34.5")]];
plot2.graphPoints = graphPointsMutableArray;
和一个NSMutableArray
的{{1}}分配给NSArray
你想要
LMGraphPoint
即。删除plot2.graphPoints
数组文字。