更多'%'转换比数据参数

时间:2014-04-18 16:38:03

标签: ios image uicollectionview parse-platform

在DetailView中我试图从Parse.com后端显示多个图像,所以我有这个代码:

编辑:

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

static NSString *cellIdentifier = @"Cell";
VestimentaDetailCell *cell = (VestimentaDetailCell *) [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];

static int index = 1;
PFFile *imageFile = [self.vestimenta objectForKey:[NSString stringWithFormat:@"image_%d", index ]];

[imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {

cell.imageFile.image = [UIImage imageWithData:data];


}
}];

return cell;
}

它有效..问题是,一旦用户查看了图像,一旦它们不再出现。

所以我尝试了实施:

PFFile *imageFile = [self.vestimenta objectForKey:[NSString stringWithFormat:@"image_%d"]];

然后我得到了错误#34;更多'%'转换比数据参数。 如何设置代码?

3 个答案:

答案 0 :(得分:2)

更改

PFFile *imageFile = [self.vestimenta objectForKey:[NSString stringWithFormat:@"image_%d"]];

PFFile *imageFile = [self.vestimenta objectForKey:[NSString stringWithFormat:@"image_%@", index ]];

当你写NSLog(@" %d %f %@")之类的东西时,你应该传递这样的参数:

NSLog(@"%d %f %@", someInt, someFloat, someString);

你可以试试这个:

PFFile *imageFile = [self.vestimenta objectForKey:[NSString stringWithFormat:@"image_%d+1", indexPath.row ]];

希望有所帮助。

答案 1 :(得分:0)

您需要以字符串格式提供%d的参数。

也许你需要这个:

PFFile *imageFile = [self.vestimenta objectForKey:[NSString stringWithFormat:@"image_%d", index]];

答案 2 :(得分:0)

在这些问题的所有答案的帮助下,我想出来了。

以下是遇到相同问题的任何人的代码:

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

static NSString *cellIdentifier = @"Cell";
VestimentaDetailCell *cell = (VestimentaDetailCell *) [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];

PFFile *imageFile = [self.vestimenta objectForKey:[NSString stringWithFormat:@"image_%d", indexPath.row]];

[imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {

cell.imageFile.image = [UIImage imageWithData:data];

    }
}];

return cell;
}