2013-05-19 39 views
0

我正在使用Parse.com检索我的数据。我想通过pf查询从解析中检索我的图像,但是我的方法无法正常工作。我的UIImageView没有任何位置。这里是我的代码:如何通过iOS查询从Parse.com中检索图像?

PFQuery *query = [PFQuery queryWithClassName:@"Class"]; 
     [query whereKey:@"Yes or No" equalTo:[NSNumber numberWithBool:YES]]; 
     [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 


      if (!error) { 
       // The find succeeded. 
       NSLog(@"Successfully retrieved %d scores.", objects.count); 



       for (int i = 0; i < objects.count; i++) { 

        object = [objects objectAtIndex:i]; 

        NSString *Property1 = [object objectForKey:@"Property1"]; 

        __block UIImage *MyPicture = [[UIImage alloc]init]; 


        PFFile *imageFile = [object objectForKey:@"Resimler"]; 
        [imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error){ 
         if (!error) { 
         MyPicture = [UIImage imageWithData:data]; 

         } 
        }]; 

aClass *AC = [[aClass alloc]initWithProperty:Propert1 Picture:MyPicture]; 
        [self.MyArray addObject:AC]; 



    } 

      } 


     } else { 
      // Log details of the failure 
      NSLog(@"Error: %@ %@", error, [error userInfo]); 
     } 


    }]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    MyViewViewCell *cell = (MyViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

    if (cell == nil) 
    { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"Cell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 
    } 


    aClass *mC = [self.MyArray objectAtIndex:indexPath.row]; 

    cell.Label.text = mC.Property; 

    cell.myImage.image = mC.Picture; 
    return cell; 
} 

编辑:

At aClass.h 
@interface aClass : NSObject 
@property(strong)NSString *Property; 

@property(strong)UIImage *Resim; 

-(id)initWithProperty:(NSString *)aProperty Picture:(UIImage *)aPicture ; 
@end 

at aClass.m 


@implementation Mekan 
@synthesize Property, Picture; 

-(id)initWithMekanIsmi:(NSString *)aProperty Picture:(UIImage *)aPicture{ 
    self=[super init]; 
    if(self){ 
     self.Property = aProperty; 
     self.Picture = aPicture; 
    } 
    return self; 

} 
@end 

我知道这是怎么样的一个质量代码,但我必须写这些代码来说明其中i分配MYIMAGE。所以,你可以问你不懂

+0

我没有看到你的代码中你指定你的UIImageView。 –

+0

考虑添加类似'NSLog(@“无错误”);'在你分配'MyPicture = [UIImage imageWithData:data]'的上方,'以确保正在触发。 –

+0

我在NSLog没有得到错误消息,我会尝试添加我分配UIImageView的位置。 – user2393702

回答

0

我不喜欢这样写道:

UIImageView *imageView = [[UIImageView alloc] initWithImage:@"default.png"]; 
[userIcon getDataInBackgroundWithBlock:^(NSData *data, NSError *error) { 
    imageView.image = [[UIImage alloc] initWithData:data]; 
} progressBlock:^(int percentDone) { 
    // update progress 
}]; 

你似乎是正确的将其分配给一个UIImage,但从来没有设置该图像作为一个UIImageView图像。

+0

你可以检查我的编辑找到我设置UIImageView – user2393702

+0

你的代码是很难遵循,因为你使用所有这些自定义类,我不知道他们是什么。看起来你的'aClass'函数就像字典,然后被卡在一个数组中。我会移动'aClass * AC = [[aClass alloc] initWithProperty:Propert1 Picture:MyPicture]; ('error')块中,然后执行一个'NSLog(@“%@”,self.MyArray);''确保它添加每一个以启动。 –

+0

我实施了你的建议。在实现'cell.Label.text = mC.Property;'之前,工作正常,但在实现您的建议后,它开始不工作。所以错误必须在if语句中。但奇怪的是,当我编写nslog时,我可以看到没有错误消息:@“没有errro”在那个if语句中。 – user2393702