Objective c 如果使用NSMutableArray而不是NSArray,则应用程序崩溃
如果我将plot2.graphPoints直接指定给一个NSArray,它可以正常工作,就像第#2行一样,但是如果我将它指定给一个NSMutableArray,就像上面显示的第一个一样,应用程序会给我Objective c 如果使用NSMutableArray而不是NSArray,则应用程序崩溃,objective-c,linegraph,Objective C,Linegraph,如果我将plot2.graphPoints直接指定给一个NSArray,它可以正常工作,就像第#2行一样,但是如果我将它指定给一个NSMutableArray,就像上面显示的第一个一样,应用程序会给我SIGABRT,下面显示了以下异常 plot2.graphPoints = graphPointsMutableArray; // plot2.graphPoints = @[LMGraphPointMake(CGPointMake(1, 25), @"1", @"34.5")]; 这就是我
SIGABRT
,下面显示了以下异常
plot2.graphPoints = graphPointsMutableArray;
// plot2.graphPoints = @[LMGraphPointMake(CGPointMake(1, 25), @"1", @"34.5")];
这就是我在NSMutableArray
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
你的两条线不相等 这: 将包含单个
LMGraphPoint
的NSArray
分配给plot2.graphPoints
而这:
plot2.graphPoints = @[LMGraphPointMake(CGPointMake(1, 25), @"1", @"34.5")];
将包含单个LMGraphPoint
的NSMutableArray
分配给plot2.graphPoints
你想要
[graphPointsMutableArray addObject:@[LMGraphPointMake(CGPointMake(1, 25), @"1", @"34.5")]];
plot2.graphPoints = graphPointsMutableArray;
即,删除@[]
数组文字
[graphPointsMutableArray addObject:@[LMGraphPointMake(CGPointMake(1, 25), @"1", @"34.5")]];
plot2.graphPoints = graphPointsMutableArray;
[graphPointsMutableArray addObject:LMGraphPointMake(CGPointMake(1, 25), @"1", @"34.5")];