0

どうすればこの問題を解決できますか..  

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
4

1 に答える 1

2

にはどのようなオブジェクトがありarrayToSortますか? 「重み」プロパティのタイプは何ですか?

推測では、一部のオブジェクトには である Weight プロパティがあり、一部のオブジェクトには である Weight プロパティNSStringがありNSNumberます。結果として、ソートは のようなことをしようとしています[someString localizedStandardCompare:someNumber]。の内部で、そのセレクターを認識しない引数を-[NSString localizedStandardCompare:]呼び出しています。-lengthNSNumber

ちなみに、プロパティ名は、頭字語やイニシャル ("URL" や "TIFF" など) で始まらない限り、小文字で始める必要があります。したがって、プロパティには「Weight」ではなく「weight」という名前を付ける必要があります。

于 2012-05-16T05:59:11.377 に答える