在 DetailView 中,我试图显示来自 Parse.com 后端的多于 1 张图像,因此我有以下代码:
编辑:
-(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"]];
但随后我收到“'%' 转换多于数据参数”的错误。 如何设置密码?
最佳答案
改变
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 ]];
希望对您有所帮助。
关于ios - 比数据参数更多的 '%' 转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23158289/