简体   繁体   English

如何将选定的集合视图单元格的图像推送到另一个视图控制器?

[英]How Can I push the image of selected Collection View Cell to another View Controller?

Can anyone please help me... I already have a collection view that displays all images from a free database on Parse.com. 谁能帮我...我已经有了一个收藏夹视图,该视图可以显示Parse.com上免费数据库中的所有图像。 I need to pass the image of the selected cell to another view controller. 我需要将所选单元格的图像传递给另一个视图控制器。 I've already have the code for prepareForSegue, my problem is that I can't get the value of the selected cell. 我已经有了prepareForSegue的代码,我的问题是我无法获取所选单元格的值。 here's my codes.. 这是我的代码。

-(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????
    }
}

I've already put codes to viewDidLoad of the recipient view controller 我已经将代码放入收件人视图控制器的viewDidLoad中

You need to make use of Delegate/Protocol. 您需要使用代理/协议。

Set the View controller that you want to send code to as a delegate in your .h file: 将要发送代码的View控制器设置为.h文件中的代理:

@interface NewSubmissionTableViewController : UITableViewController<PhotoPickerViewControllerDelegate>

import the view controller you want to send the image to at the top of your .h file. 在.h文件顶部导入要发送图像的视图控制器。

#import "PhotoPickerViewController.h"

Instantiate the VC you are sending the image too and set a variable within that class equal to the variable you want it to have access to. 还要实例化正在发送图像的VC,并在该类中设置一个变量,使其等于您希望其访问的变量。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    PhotoPickerViewController *photoPicker = segue.destinationViewController;
    photoPicker.delegate = self;
    photoPicker.selectedPhotos = self.pictureCollection;
}
(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [self prepareForSegue:<#(UIStoryboardSegue *)#> sender:<#(id)#>]
}

-(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"])
    {
        transferViewController.xxx = sender;
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我轻按任何集合视图单元格时(不点击最后一个单元格),如何移动另一个视图控制器? - How to move another view controller when i tapped any collection view cell (without taping last cell)? 如何将集合视图单元格的indexPath传递给另一个视图控制器 - How to pass a collection view cell's indexPath to another view controller 如何根据选定的单元格将segue推送到特定的View Controller? - How to push segue to specific View Controller depending on a selected cell? 如何从情节提要中的子视图(另一个视图控制器)内的按钮推动新的视图控制器 - How can I push a new View Controller from a button within a subView (another View Controller) in Storyboard 如何将数据从集合视图单元传递到新的视图控制器(以编程方式且没有情节提要)? - How can I passed data from collection view cell to new view controller (programmatically and without storyboard)? 如何将选定的collectionview单元格发送到另一个视图控制器(ios)? - How to send a selected collectionview cell to another view controller (ios)? 如何将选定单元格中的数据传递给另一个视图控制器? - How to pass data in selected cell to another view controller? iOS如何将选定的单元格值隔离到另一个视图控制器中 - iOS how to segue a selected cell value into another view controller 如何将新的viewController推送到另一个视图控制器中的现有视图? - How can I push a new viewController into an existing view within another view controller? 如何在嵌套集合视图单元 swift 中的按钮点击上推送视图控制器 - How to push view controller on a button tap in nested collection view cell swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM