Parseバックエンドからデータをロードしたテーブルビューを取得して、テーブル内のデータに関連付けられた画像(PFFile)を含む詳細ビューをプッシュしようとしています。データをテーブルに正常にロードできますが、新しいViewControllerにセグエするとアプリがクラッシュします。これが私のPFQueryTableViewController実装からのコードです。
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithClassName:@"Wine"];
self = [super initWithCoder:aDecoder];
if (self) {
self.className = @"Wine";
self.textKey = @"Name";
self.pullToRefreshEnabled = YES;
self.paginationEnabled = YES;
self.objectsPerPage = 50;
self.sections = [NSMutableDictionary dictionary];
self.sectionToWineTypeMap = [NSMutableDictionary dictionary];
}
return self;
}
- (void)viewWillAppear:(BOOL)animated
{
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.png"]];
[self.tableView setBackgroundView:imageView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.sections.allKeys.count;
}
- (NSString *)wineTypeForSection:(NSInteger)section {
return [self.sectionToWineTypeMap objectForKey:[NSNumber numberWithInt:section]];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSString *wineType = [self wineTypeForSection:section];
NSArray *rowIndecesInSection = [self.sections objectForKey:wineType]; return rowIndecesInSection.count;
}
- (CGFloat)tableView:(UITableView *)tableView
heightForHeaderInSection:(NSInteger)section {
return 40;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UILabel *sectionHeader = [[UILabel alloc] initWithFrame:CGRectNull];
sectionHeader.backgroundColor = [UIColor groupTableViewBackgroundColor];
sectionHeader.textAlignment = UITextAlignmentCenter;
sectionHeader.font = [UIFont boldSystemFontOfSize:17];
sectionHeader.textColor = [UIColor whiteColor];
sectionHeader.text = [self wineTypeForSection:section];
return sectionHeader;
}
- (void)objectsDidLoad:(NSError *)error {
[super objectsDidLoad:error];
[self.sections removeAllObjects];
[self.sectionToWineTypeMap removeAllObjects];
NSInteger section = 0;
NSInteger rowIndex = 0;
for (PFObject *object in self.objects) {
NSString *wineType = [object objectForKey:@"wineType"];
NSMutableArray *objectsInSection = [self.sections objectForKey:wineType];
if (!objectsInSection) {
objectsInSection = [NSMutableArray array];
[self.sectionToWineTypeMap setObject:wineType forKey:[NSNumber numberWithInt:section++]];
}
[objectsInSection addObject:[NSNumber numberWithInt:rowIndex++]];
[self.sections setObject:objectsInSection forKey:wineType];
}
}
- (PFQuery *)queryForTable {
PFQuery *query = [PFQuery queryWithClassName:self.className];
if (self.pullToRefreshEnabled) {
query.cachePolicy = kPFCachePolicyNetworkOnly;
}
if (self.objects.count == 0) {
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}
[query orderByAscending:@"orderIndex"];
return query;
}
- (PFObject *)objectAtIndexPath:(NSIndexPath *)indexPath {
NSString *wineType = [self wineTypeForSection:indexPath.section];
NSArray *rowIndecesInSection = [self.sections objectForKey:wineType];
NSNumber *rowIndex = [rowIndecesInSection objectAtIndex:indexPath.row];
return [self.objects objectAtIndex:[rowIndex intValue]];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
static NSString *CellIdentifier = @"WineCell";
PFTableViewCell *cell = (PFTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[PFTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [object objectForKey:@"Name"];
cell.detailTextLabel.text = [object objectForKey:@"Price"];
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"ShowWine"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
PFObject *object = [self.objects objectAtIndex:indexPath.row];
PFFile *file = [object objectForKey:@"image"];
[[segue destinationViewController] setFile:file];
}
}
そして、これが詳細ビューコントローラーヘッダーと実装からのコードです
@property (nonatomic, retain) PFFile *file;
@property (nonatomic, retain) PFImageView *detailImage;
実装
@implementation DetailVC
@synthesize file;
@synthesize detailImage;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(void)viewDidAppear:(BOOL)animated
{
detailImage.file = file;
// Now tell PFImageView to download the file asynchronously
[detailImage loadInBackground];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
そして、これが私が受け取っているエラーメッセージです。
キャッチされなかった例外'NSUnknownKeyException'が原因でアプリを終了しています、理由:'[setValue:forUndefinedKey:]:このクラスはキーの詳細についてコーディングに準拠したキー値ではありません。