【发布时间】:2012-11-08 13:43:51
【问题描述】:
我正在尝试将 NSMutableArray* 复制到 NSArray* 中,但它不起作用并且会生成 [__NSCFString superview]: unrecognized selector sent to instance 错误。代码如下:
//where gc is a NSDictionary*, recentKey is a NSString*, and _objects is a NSArray*
//gc is an singleton is used to save chache data, with NSKeyedUnarchiver class
//_objects is used to reload the UITableView's data
NSArray *savedNews = [[NSArray alloc] initWithArray:[gc objectForKey:recentkey]];
//this not works...why??
_objects = [[NSArray alloc] initWithArray:savedNews];
分辨率:
是的,正如赫尔曼所说,错误是外部的。 savedNews 数组使用带有 NSEncoding 的类,但出现错误:
- (void)encodeWithCoder:(NSCoder *)encoder {
//...where element was NSString* and not "UIImageView"
// element should be imgView
if (imgView) [encoder encodeObject:element forKey:@"imgView"];
}
谢谢大家。
【问题讨论】:
-
哪一行失败了?你确定你在上下文中发布了所有代码吗?
-
_objects 是一个 NSArray*。失败的行是_objects的分配。
标签: objective-c ios memory nsarray unrecognized-selector