我的单元格显示用户已拍摄并添加到UICollectionView
的图像。在API服务器上,这些图像由timestamp
组织(见下文),这意味着在应用程序中,显示的第一个单元格是上传到服务器的最新图像。
在服务器上,它看起来像这样:
results: [
{
i_id: "28",
title: "image title",
description: "Picture",
longitude: "0.000000",
latitude: "0.000000",
filename: "http://server.com/images/image.jpg",
timestamp: "12:34:04",
n_likes: "0",
n_comments: "1",
images: {
}
},
{
i_id: "21",
title: "another image title"
description: "another Picture",
longitude: "0.000000",
latitude: "0.000000",
filename: "http://server.com/images/image.jpg",
timestamp: "12:20:49",
image: "",
n_likes: "2",
n_comments: "4",
images: {
}
}
]
我能够将每个图像的n_comments
数据放入数组中而不会出现问题。我希望数组计算索引处每个对象的数字,并根据对象包含的数字(如果有意义)确定首先显示在UICollectionView
中的数字。
这是我必须在服务器上管理的东西,还是我可以在应用程序的代码中执行此操作?我猜这与UICollectionViewLayout
有关,所以我会在此期间尝试让它工作。
任何建议都将不胜感激!感谢。
答案 0 :(得分:0)
您可以在任何一端执行此操作,但您无需对UICollectionViewFlowLayout执行任何操作。在应用程序端,您可以使用sortedArrayUsingDescriptors对数组进行排序:使用sortDescriptorWithKey:ascending:的描述符,将n_comments作为键传递。