基本的に、配列内のオブジェクトをy値で並べ替えています(ページの一番下が配列の先頭にあります)が、少し問題があります。配列内のすべてのUIImageViewに値を割り当てます。
for (UIImageView *Blocky in objectsArray){
[Blocky.layer setValue:[NSString stringWithFormat: @"%f",
Blocky.center.y] forKey:@"value"];
}
UIImageViewであるため、「Blocky」の後にレイヤーを配置する必要があります。そうしないと、次のエラーが発生します。
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIImageView 0x3d44880> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key value.'
私の問題は、並べ替えるときに「.layer」を配置する場所がわからないため、UIImageViewsがそれ自体でキーを処理できないため、同じ問題が発生することです。これが私のソートコードです:
NSSortDescriptor *sortDescriptor =
[[NSSortDescriptor alloc] initWithKey:@"value" ascending:YES];
[objectsArray sortUsingDescriptors:[NSArray
arrayWithObject:sortDescriptor]];
[sortDescriptor release];
よろしくお願いします、オジー