I have a NSMutableArray
that I've initialised in viewDidLoad
:
我在viewDidLoad初始化了一个NSMutableArray:
self.titlesTagArreys = [@[@"Dollar", @"Euro", @"Pound",@"Dollar longString", @"Euro longStringlongString", @"Pound",@"Dollar", @"Euro", @"PoundlongStringlongString"]mutableCopy];
in .h:
. h:
@property(nonatomic, copy) NSMutableArray* titlesTagArreys;
When I try to delete one item, the app crashes:
当我试图删除一个条目时,应用程序崩溃了:
-(void)removeButtonWasPressed:(NSString*)tagTitle{
NSLog(@"tagTitle - %@",tagTitle);
NSLog(@"self.titlesTagArreys - %@",self.titlesTagArreys);
[self.titlesTagArreys removeObject:tagTitle];
}
Here is the log:
这是日志:
2013-08-06 16:15:03.989 EpicTv[6378:907] tagTitle - Dollar
2013-08-06 16:15:03.991 EpicTv[6378:907] self.titlesTagArreys - (
Dollar,
Euro,
Pound,
"Dollar longString",
"Euro longStringlongString",
Pound,
Dollar,
Euro,
PoundlongStringlongString
)
[__NSArrayI removeObject:]: unrecognized selector sent to instance 0x1c53bbd0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI removeObject:]: unrecognized selector sent to instance 0x1c53bbd0'
*** First throw call stack:
(0x327162a3 0x3a5c197f 0x32719e07 0x32718531 0x3266ff68 0x20ad55 0x20c9a5 0x20bf5d 0x346090c5 0x34609077 0x34609055 0x3460890b 0x34608e01 0x345315f1 0x3451e801 0x3451e11b 0x362295a3 0x362291d3 0x326eb173 0x326eb117 0x326e9f99 0x3265cebd 0x3265cd49 0x362282eb 0x34572301 0xafb89 0xa4d68)
libc++abi.dylib: terminate called throwing an exception
4 个解决方案
#1
6
It seems that titlesTagArray
s list not an NSMutableArray
because removeObject
can not be called. Maybe you passed an NSArray
earlier in the code to titlesTagArreys
.
似乎titlestagarray列出的不是NSMutableArray,因为removeObject不能被调用。也许您在代码的前面已经将一个NSArray传递给了titlesTagArreys。
try to init
your Array with
尝试初始化数组
self.titlesTagArreys = [NSMutableArray arrayWithArray:@[@"...",@"...",...]];
@property(nonatomic, copy) makes a not mutable copy of you NSMutableArray. try @property(nonatomic, retain) instead of copy
@property(nonatomic, copy)使您无法更改NSMutableArray的副本。尝试@property(非原子,retain)而不是copy
#2
5
I also think that you titlesTagArreys
is not mutable array because of some code changes
我还认为您titlesTagArreys不是可变数组,因为一些代码更改
Try to add: NSLog(@"%@", NSStringFromClass(self.titlesTagArreys.class));
to check what class do you use
尝试添加:NSLog(@“%@”,NSStringFromClass(self. titlestagris .class);检查你使用什么类
-(void)removeButtonWasPressed:(NSString*)tagTitle{
NSLog(@"%@", NSStringFromClass(self.titlesTagArreys.class));
[self.titlesTagArreys removeObject:tagTitle];
}
#3
0
I had the same problem and learned that you must override the setter for the mutable array property and call mutableCopy
. You'll find the answer in Stack Overflow here.
我也遇到了同样的问题,我知道您必须重写可变数组属性的setter并调用mutableCopy。您将在这里找到堆栈溢出的答案。
#4
0
titlesTagArray is not NSMutableArray. This is because , in the logs we can see [__NSArrayI removeObject:] unrecognized selector sent to instance 0x1c53bbd0. Also NSArrayI is used for NSArray and NSArrayM is used for NSMutableArray. You must have initialised the mutablearray with an NSArray hence the exception.
titlesTagArray不是NSMutableArray。这是因为,在日志中我们可以看到[__NSArrayI removeObject:]无法识别的选择器发送给实例0x1c53bbd0。NSArrayI用于NSArray NSArrayM用于NSMutableArray。您必须使用NSArray初始化mutablearray,这是一个例外。
#1
6
It seems that titlesTagArray
s list not an NSMutableArray
because removeObject
can not be called. Maybe you passed an NSArray
earlier in the code to titlesTagArreys
.
似乎titlestagarray列出的不是NSMutableArray,因为removeObject不能被调用。也许您在代码的前面已经将一个NSArray传递给了titlesTagArreys。
try to init
your Array with
尝试初始化数组
self.titlesTagArreys = [NSMutableArray arrayWithArray:@[@"...",@"...",...]];
@property(nonatomic, copy) makes a not mutable copy of you NSMutableArray. try @property(nonatomic, retain) instead of copy
@property(nonatomic, copy)使您无法更改NSMutableArray的副本。尝试@property(非原子,retain)而不是copy
#2
5
I also think that you titlesTagArreys
is not mutable array because of some code changes
我还认为您titlesTagArreys不是可变数组,因为一些代码更改
Try to add: NSLog(@"%@", NSStringFromClass(self.titlesTagArreys.class));
to check what class do you use
尝试添加:NSLog(@“%@”,NSStringFromClass(self. titlestagris .class);检查你使用什么类
-(void)removeButtonWasPressed:(NSString*)tagTitle{
NSLog(@"%@", NSStringFromClass(self.titlesTagArreys.class));
[self.titlesTagArreys removeObject:tagTitle];
}
#3
0
I had the same problem and learned that you must override the setter for the mutable array property and call mutableCopy
. You'll find the answer in Stack Overflow here.
我也遇到了同样的问题,我知道您必须重写可变数组属性的setter并调用mutableCopy。您将在这里找到堆栈溢出的答案。
#4
0
titlesTagArray is not NSMutableArray. This is because , in the logs we can see [__NSArrayI removeObject:] unrecognized selector sent to instance 0x1c53bbd0. Also NSArrayI is used for NSArray and NSArrayM is used for NSMutableArray. You must have initialised the mutablearray with an NSArray hence the exception.
titlesTagArray不是NSMutableArray。这是因为,在日志中我们可以看到[__NSArrayI removeObject:]无法识别的选择器发送给实例0x1c53bbd0。NSArrayI用于NSArray NSArrayM用于NSMutableArray。您必须使用NSArray初始化mutablearray,这是一个例外。