2013-05-19 38 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