将PFFile传递给新视图时,我要么没有图像,要么图像错误。
这是prepareForSegue方法
- (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];
}
}
我的相关实现文件的其余部分,我只是认为我没有在右边的部分找到正确的行?
- (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;
}
- (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];
}
}
- (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]];
}
答案 0 :(得分:0)
您应该尝试做的事情如下:
didSelectRowAtIndexPath:
中,调用objectAtIndexPath:
方法,并使用返回值设置aFile
didSelectRowAtIndexPath:
,请致电performSegueWithIdentifier:
并在prepareForSegue:
,只需将目标文件设置为var:[[segue destinationViewController] setFile: aFile];
。试试这个,看看它是否效果更好。如果没有,请告诉我!