UICollectionView 并使用 Parse 推送到 detailViewController [英] UICollectionView and push to detailViewController using Parse

查看:23
本文介绍了UICollectionView 并使用 Parse 推送到 detailViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 tapGesture 方法将图像从 UICollectionView 装袋到 detailViewControllerviewController.h 如下:

I use the tapGesture method to pouch the image from UICollectionView to detailViewController viewController.h as follows:

#import <Parse/Parse.h>


@interface CardsViewController : UIViewController <UICollectionViewDelegateFlowLayout> {
    NSMutableArray *allImages;
    NSArray *cardFileArray;
}

@property (weak, nonatomic) IBOutlet UICollectionView *imageCollection

和 viewController.m 如下

and viewController.m as the follow

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return [cardFileArray count];
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *identifier = @"MyCell";

    Cards *cell = (Cards *)[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

    PFObject *imageObject = [cardFileArray objectAtIndex:indexPath.row];
    PFFile *imageFile = [imageObject objectForKey:KEY_IMAGE4];

    cell.spinController.hidden = NO;
    [cell.spinController startAnimating];

    [imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
        if (!error) {
            cell.imageView.image = [UIImage imageWithData:data];
            [cell.spinController stopAnimating];
            cell.spinController.hidden = YES;

        }
    }];




    return cell;
}

- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture{

    CGPoint touchPoint = [gesture locationInView:imageCollection];
    NSUInteger touchPage = floorf(touchPoint.x / imageCollection.frame.size.width);

    NSIndexPath *indexPath = [imageCollection indexPathForItemAtPoint:touchPoint];

    if (indexPath == nil) {
        touchPage = touchPage % ([allImages count]);
    }


    //Push the image to another view
    detailViewController*ptvc = [self.storyboard instantiateViewControllerWithIdentifier:@"imageDetail"];
    [self.navigationController pushViewController:ptvc animated:YES];
    ptvc.imageString = [cardFileArray objectAtIndex:touchedPage];

 }

detailViewController.h 如下

the detailViewController.h as follow

@property (strong, nonatomic) IBOutlet UIImageView *Preview;
@property (strong, nonatomic) UIImage *imagePreview;

所以对于 DetailViewController 我把这行放在 viewDidload 中

so for the DetailViewController i put in viewDidload this line

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //self.imageView.image = [UIImage imageNamed:self.imageViewDetail];
    self.Preview.image = self.imagePreview;



}

但应用程序崩溃并在 viewDidload 上标记该行;所以我需要将 uicollectionView 上的图像推送到 detailView 的任何建议

but the app make crash and mark the line on the viewDidload ; so any advice i need to puch the image on uicollectionView to detailView

推荐答案

要解决这个问题,首先需要从解析中识别didselect中的图像并声明segue以及以下

to solve this first you need to identify the image in didselect from parse and declare the segue as well as following

[self performSegueWithIdentifier:@"showDetails" sender:imageCollection];
    PFObject *object = [cardFileArray objectAtIndex:indexPath.row];
    PFFile *file = [object objectForKey:KEY_IMAGE4];

    [file getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
        if (!error) {

            Cards *recipe = [[Cards alloc] init];
            recipe.imageView.image = [UIImage imageWithData:data];

        }
    }];

然后您执行 Segue 方法并像往常一样链接到详细信息视图,而不是以下

then you perform the Segue method and link to the detail view as normal and not the following

将您链接到您的单元格"和单元格中的图像视图

link you segue to the "you cell" and the imageview in the cell

最后,将您的单元格导入详细信息视图并在您的头文件中声明它(这将链接到您的 segue)

Finally, import your cell to the detail view and declare it in your header file (this will be linked to your segue)

希望对你有帮助

这篇关于UICollectionView 并使用 Parse 推送到 detailViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆