请给我一些建议,我该如何解决这个问题呢?3.
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Weight" ascending:NO selector:@selector(localizedStandardCompare:)];
NSArray *sortedArray = [arrayToSort sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];我正在获得输出:
-[__NSCFNumber length]: unrecognized selector sent to instance 0x6a81cf0
2012-05-16 09:54:21.480 MedzioSearch[2188:f803] *** WebKit discarded an uncaught exception in the webView:shouldInsertText:replacingDOMRange:givenAction: delegate: <NSInvalidArgumentException> -[__NSCFNumber length]: unrecognized selector sent to instance 0x6a81cf0发布于 2012-05-16 13:59:11
arrayToSort中有哪些类型的对象?他们的“权重”属性的类型是什么?
根据猜测,一些对象具有NSString属性,而另一些对象具有NSNumber属性。因此,排序正在尝试做一些类似于[someString localizedStandardCompare:someNumber]的事情。在-[NSString localizedStandardCompare:]内部,它在参数上调用-length,该参数是一个NSNumber,无法识别该选择器。
顺便说一下,属性名称应该以小写字母开头,除非它们以首字母缩写或缩写开头(如"URL“或"TIFF")。所以,你的属性应该被命名为"weight",而不是"Weight“。
https://stackoverflow.com/questions/10612547
复制相似问题