任何人都可以請幫助我...我已經有一個集合視圖,顯示來自Parse.com上免費數據庫的所有圖像。我需要將選定單元格的圖像傳遞給另一個視圖控制器。我已經有了prepareForSegue的代碼,我的問題是我無法獲得所選單元格的值。這裏是我的代碼..如何將所選集合視圖單元的圖像推送到另一個視圖控制器?
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [imageArray count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"imageCell";
GalleryCell *cell = (GalleryCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
PFObject *imageObject = [imageArray objectAtIndex:indexPath.row];
PFFile *imageFile = [imageObject objectForKey:@"parseImage"];
cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"photo-frame.png"]];
cell.loadingSpinner.hidden = NO;
[cell.loadingSpinner startAnimating];
[imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {
cell.parseImage.image = [UIImage imageWithData:data];
[cell.loadingSpinner stopAnimating];
cell.loadingSpinner.hidden = YES;
}
}];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
// should I put anything here? the collection view display images even its blank
}
//segue transfer data
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
UINavigationController *nav = [segue destinationViewController];
DetailedVC *transferViewController = (DetailedVC *)nav.topViewController;
NSLog(@"prepareForSegue: %@", segue.identifier);
if([segue.identifier isEqualToString:@"detailView"])
{
//here is my problem... what should I put here????
}
}
我已經把代碼viewDidLoad中查看收件人的控制器
感謝您的答覆..我來試試 – user3317412
IM在這個行 有錯誤[自prepareForSegue:(UIStoryboardSegue *)發件人:(ID)]; 它說使用未聲明的標識符'發件人' – user3317412
也許你應該在「(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath」獲取單元格,然後將此單元格變爲「GalleryCell」,然後獲取來自細胞的圖像。 –