1

将 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]];
}
4

1 回答 1

0

您应该尝试执行以下操作:

  1. 创建实例变量 (PFFile *aFile)
  2. didSelectRowAtIndexPath:,调用你的objectAtIndexPath:方法,并设置aFile返回值
  3. 仍然在didSelectRowAtIndexPath:,调用你的performSegueWithIdentifier:和 in prepareForSegue:,只需将目标文件设置为你的 var [[segue destinationViewController] setFile: aFile];:。

试试这个,看看它是否效果更好。如果没有,请告诉我!

于 2012-10-09T10:08:09.083 回答