【问题标题】:More '%' conversions than data arguments比数据参数更多的“%”转换
【发布时间】:2014-06-03 05:01:22
【问题描述】:

在 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"]];

但随后我收到“更多 '%' 转换比数据参数。 如何设置代码?

【问题讨论】:

    标签: ios image uicollectionview parse-platform


    【解决方案1】:

    改变

    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 ]];
    

    希望有所帮助。

    【讨论】:

    • 我得到一个格式字符串问题:“格式指定类型 'int' 但参数的类型为 'char ()(const char*,int)' 但如果我保留:static int index = 1;然后单个图像在所有单元格中重复。
    • 请尝试我更新的答案。告诉我们你的图像字符串到底长什么样,什么是索引?在控制台中显示它
    • 我做了,我得到了那个错误。我的字符串是 image_1、image_2、image_3 等等。我已经编辑了我的代码,现在的方式显示 image_1 在所有单元格中重复。
    • 您需要传递正确的图像字符串并为每个单元格更改它,我猜您没有更改图像,您需要找到一种方法来为每个单元格更改它。
    • 想通了!谢谢你。下面是代码:PFFile *imageFile = [self.vestimenta objectForKey:[NSString stringWithFormat:@"image_%d", indexPath.row]];
    【解决方案2】:

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

    也许你需要这个:

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

    【讨论】:

    • 我收到格式字符串问题:“格式指定类型 'int' 但参数的类型为 'char ()(const char*,int)' 但如果我保留: static int index = 1; 然后单个图像在所有单元格中重复。
    • 什么是index?是int 还是别的什么?
    • 是的,它是一个整数。我已经编辑了我的代码。它现在的显示方式显示单个图像,在这种情况下,第一个图像会在所有单元格中重复。
    【解决方案3】:

    在这个问题的所有答案的帮助下,我想通了。

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

    -(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;
    }
    

    【讨论】:

      猜你喜欢
      • 2015-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-31
      • 1970-01-01
      • 1970-01-01
      • 2018-10-05
      相关资源
      最近更新 更多