本文介绍了问题复制的NSMutableArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想一个阵列复制到另一个:
的NSMutableArray * itemsCopy = [[NSMutableArray里的alloc] initWithArray:self.items copyItems:YES];
但我得到的错误:
***终止应用程序由于未捕获的异常'NSInvalidArgumentException',原因:' - [项目copyWithZone:]:无法识别的选择发送到实例0x5a74900
在第一掷***调用堆栈:
(
0的CoreFoundation 0x025afc99 __exception preprocess + 185
1 libobjc.A.dylib 0x026fd5de objc_exception_throw + 47
2的CoreFoundation 0x025b17ab - [NSObject的(NSObject的)doesNotRecognizeSelector:] + 187
3的CoreFoundation 0x02521496 ___forwarding___ + 966
4的CoreFoundation 0x02521052 _CF_forwarding_ prep_0 + 50
5的CoreFoundation 0x025108fa - [NSObject的(NSObject的)复制] + 42
6的CoreFoundation 0x025ab732 - [NSArray的initWithArray:范围:copyItems:] + 290
7的CoreFoundation 0x02513963 - [NSArray的initWithArray:copyItems:] + 99
8 MyViewController 0x0000787d - [MyViewController的tableView:didSelectRowAtIndexPath方法:] + 258
9 UIKit的0x003968f8 - [UITableView的_selectRowAtIndexPath:动画:的scrollPosition:notifyDelegate:] + 1140
10 UIKit的0x0038d1de - [UITableView的_userSelectRowAtIndexPath:] + 219
11基金0x000a404e __NSFireDelayedPerform + 441
12的CoreFoundation 0x025910c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
13的CoreFoundation 0x02592704 __CFRunLoopDoTimer + 1364
14的CoreFoundation 0x024ef089 __CFRunLoopRun + 1817
15的CoreFoundation 0x024ee600 CFRunLoopRunSpecific + 208
16的CoreFoundation 0x024ee521 CFRunLoopRunInMode + 97
17 GraphicsServices 0x02db52c8 GSEventRunModal + 217
18 GraphicsServices 0x02db538d GSEventRun + 115
19 UIKit的0x00332e8f UIApplicationMain + 1160
20 MyViewController 0x0000210c主+ 102
21 MyViewController 0x0000209d启动+ 53
)
扔NSException的一个实例后终止叫
解决方案
您需要确保所有的内容的 self.items
的采用在NSCopying协议。
如果你只是想要一个浅拷贝,发送 -mutableCopy
消息 self.items
。
的NSMutableArray * itemsCopy = [self.items mutableCopy]
I am trying to copy one array to another:
NSMutableArray *itemsCopy = [[NSMutableArray alloc] initWithArray:self.items copyItems:YES];
but I get the error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Item copyWithZone:]: unrecognized selector sent to instance 0x5a74900'
*** Call stack at first throw:
(
0 CoreFoundation 0x025afc99 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x026fd5de objc_exception_throw + 47
2 CoreFoundation 0x025b17ab -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x02521496 ___forwarding___ + 966
4 CoreFoundation 0x02521052 _CF_forwarding_prep_0 + 50
5 CoreFoundation 0x025108fa -[NSObject(NSObject) copy] + 42
6 CoreFoundation 0x025ab732 -[NSArray initWithArray:range:copyItems:] + 290
7 CoreFoundation 0x02513963 -[NSArray initWithArray:copyItems:] + 99
8 MyViewController 0x0000787d -[MyViewController tableView:didSelectRowAtIndexPath:] + 258
9 UIKit 0x003968f8 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1140
10 UIKit 0x0038d1de -[UITableView _userSelectRowAtIndexPath:] + 219
11 Foundation 0x000a404e __NSFireDelayedPerform + 441
12 CoreFoundation 0x025910c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
13 CoreFoundation 0x02592704 __CFRunLoopDoTimer + 1364
14 CoreFoundation 0x024ef089 __CFRunLoopRun + 1817
15 CoreFoundation 0x024ee600 CFRunLoopRunSpecific + 208
16 CoreFoundation 0x024ee521 CFRunLoopRunInMode + 97
17 GraphicsServices 0x02db52c8 GSEventRunModal + 217
18 GraphicsServices 0x02db538d GSEventRun + 115
19 UIKit 0x00332e8f UIApplicationMain + 1160
20 MyViewController 0x0000210c main + 102
21 MyViewController 0x0000209d start + 53
)
terminate called after throwing an instance of 'NSException'
解决方案
You need to make sure all the contents of self.items
adopt the NSCopying protocol.
If you just want a shallow copy, send the -mutableCopy
message to self.items
.
NSMutableArray *itemsCopy = [self.items mutableCopy];
这篇关于问题复制的NSMutableArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!