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

나는 그것이 대량 코드의 종류 알고 있지만 내가 myimage을을 할당 할 경우 설명하기 위해 그 코드를 작성해야합니다. 당신이

+0

UIImageView를 할당하는 코드가 표시되지 않습니다. –

+0

'MyPicture = [UIImage imageWithData : data];를 지정하는 곳 바로 위에'NSLog (@ "No Error");와 같은 것을 추가하는 것을 고려해보십시오. –

+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];를 움직일 것이다. // (% @ ", self.MyArray);'를 수행하기 위해 각각을 추가하는지 확인하기 위해 (NSLog (@"% @ ", self.MyArray);) . –

+0

귀하의 제안을 이행했습니다. 구현하기 전에'cell.Label.text = mC.Property;'는 잘 동작하지만 제안을 구현 한 후에는 작동하지 않는다. 따라서 if 문에 오류가 있어야합니다. 하지만 이상한 것은 내가 nslog를 작성할 때 오류 메시지가 표시되지 않는다는 것입니다. @ "no errro"가 if 문입니다. – user2393702

관련 문제