class不是密钥tableData的密钥值编码兼容

时间:2015-01-11 03:57:21

标签: ios objective-c json

以下是我的代码。

#import "PhotoGalleryTableViewController.h"
#import "AppDelegate.h"

#define kPhotoGalleryURL [NSURL URLWithString:@"https://www.kimonolabs.com/api/2v35aqn0?apikey=xgp4nU6xA9UcBWSe0MIHcBVbAWz5v4wR"]


@interface PhotoGalleryTableViewController ()

@property (nonatomic, strong) NSArray *photoGallery;

@end

@implementation PhotoGalleryTableViewController

- (void)viewDidLoad {
[super viewDidLoad];


dispatch_async(kBgQueue, ^{
    NSData *data = [NSData dataWithContentsOfURL:kPhotoGalleryURL];
    [self performSelectorOnMainThread:@selector(fetchedGalleryData:) withObject:data waitUntilDone:YES];
});
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.

}

-(void)fetchedGalleryData:(NSData *)galleryResponseData {
NSError *error;
NSDictionary *json = [NSJSONSerialization
                      JSONObjectWithData:galleryResponseData
                      options:kNilOptions
                      error:&error];
NSArray *myPhotoGallery = [[json objectForKey:@"results"]objectForKey:@"collection1"];
myPhotoGallery = self.photoGallery;
NSLog(@"%@", self.photoGallery);
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [self.photoGallery count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"galleryCell" forIndexPath:indexPath];

if (cell == nil) {
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"galleryCell"];
}

NSDictionary *galleries = [self.photoGallery objectAtIndex:indexPath.row];

NSString *description = [[galleries objectForKey:@"description"] objectForKey:@"text"];
NSMutableString *images = [[galleries objectForKey:@"photo"] objectForKey:@"src"];

NSURL *imageURL = [NSURL URLWithString:images];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *img = [[UIImage alloc] initWithData:imageData];

cell.textLabel.text = description;
cell.imageView.image = img;


return cell;
}
@end

当我运行应用程序时,我得到了这个终止应用程序,因为未捕获的异常' NSUnknownKeyException',原因:' [setValue:forUndefinedKey:]:此类不符合键值编码key tableData。'在我的控制台中。而且控制台也不会显示photoGallery数组。

我已经在appdelegate.h文件中声明了kBgQueue并导入了它。我有另一个非常相似的视图控制器,一切都很好。

提前谢谢你,抱歉这是一个负担。

0 个答案:

没有答案