基本上,我正在按 y 值对数组中的对象进行排序(页面最下方位于数组的开头),但我遇到了一些麻烦。我为数组中的所有 UIImageViews 分配了一个值:
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];
在此先感谢,奥齐