내 데이터를 검색하는 데 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을을 할당 할 경우 설명하기 위해 그 코드를 작성해야합니다. 당신이
UIImageView를 할당하는 코드가 표시되지 않습니다. –
'MyPicture = [UIImage imageWithData : data];를 지정하는 곳 바로 위에'NSLog (@ "No Error");와 같은 것을 추가하는 것을 고려해보십시오. –
NSLog에서 오류 메시지가 나타나지 않으면 UIImageView를 할당 할 위치를 추가하려고합니다. – user2393702