我使用 tapGesture 方法将图像从 UICollectionView 打包到 detailViewController viewController.h 如下:
#import <Parse/Parse.h>
@interface CardsViewController : UIViewController <UICollectionViewDelegateFlowLayout> {
NSMutableArray *allImages;
NSArray *cardFileArray;
}
@property (weak, nonatomic) IBOutlet UICollectionView *imageCollection
和viewController.m如下
- (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如下
@property (strong, nonatomic) IBOutlet UIImageView *Preview;
@property (strong, nonatomic) UIImage *imagePreview;
所以对于 DetailViewController,我在 viewDidload 中放入了这一行
- (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 的任何建议
最佳答案
要解决这个问题,首先你需要在 didselect from parse 中识别图像并声明 segue 以及以下内容
[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 方法并正常链接到详细信息 View ,而不是以下内容
链接到“you cell”和单元格中的 ImageView
最后,将您的单元格导入详细 View 并在您的头文件中声明它(这将链接到您的 segue)
希望对你有帮助
关于ios - UICollectionView 并使用 Parse 推送到 detailViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21393359/