2012-09-24 51 views
1

當傳遞一個PFFile到新的視圖時,我要麼沒有圖像或錯誤的圖像。prepareForSegue不通過正確的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

嗨,你解決了你的問題嗎? – rdurand

回答

0

你應該嘗試做如下:

  1. 與返回值
  2. 創建一個實例變量(PFFile *å文件)
  3. didSelectRowAtIndexPath:,請致電您objectAtIndexPath:方法,並設置aFile
  4. 仍然在didSelectRowAtIndexPath:,請致電performSegueWithIdentifier:prepareForSegue:,只需將目標文件設置爲您的var:[[segue destinationViewController] setFile: aFile];即可。

試試這個,看看它是否更好。如果沒有,請讓我知道!