0

我有显示用户拍摄并添加到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我希望数组计算索引处每个对象的数字,并根据对象包含的数字(如果有意义的话)确定哪个将在第一个显示。

Would this be something that I’d have to manage on the server, or can I do it within the app’s code? I’m guessing that it has to do with UICollectionViewLayout, so that’s where I’ll be attempting to get it to work in the meantime.

Any advice would be much appreciated! Thanks.

4

1 回答 1

0

You could do this on either end, but you don't need to do anything with UICollectionViewFlowLayout. On the app end, you could sort your array with sortedArrayUsingDescriptors: with a descriptor of sortDescriptorWithKey:ascending:, passing n_comments as the key.

于 2013-01-14T16:02:17.520 回答