简体   繁体   English

带有填充有数组的“集合/表”视图的明细视图?

[英]Detail views with Collection/Table Views populated with an Array?

I'm having a similar problem in two separate instances, but I feel like the solution for one problem will solve the other. 我在两个单独的实例中遇到了类似的问题,但是我觉得一个问题的解决方案将解决另一个问题。 I'm a noob. 我是菜鸟 I'm using a Collection View for a photo gallery that I have populated with an NSArray. 我正在为装有NSArray的照片集使用“收藏夹视图”。 The collection view works just fine, and populates the right images in the right order. 集合视图工作正常,并以正确的顺序填充正确的图像。 I just can't figure out how to get the detail view to work correctly with the code that I have specifically. 我只是想不通如何使细节视图与我特有的代码一起正常工作。 I have my delegates set up in the .h file: 我在.h文件中设置了我的代表:

@interface PhotoViewController : UICollectionViewController <UICollectionViewDelegate, UICollectionViewDataSource>

The NSArray looks like this: NSArray看起来像这样:

#import "PhotoViewController.h"
#import "PhotoViewCell.h"
#import "ImageDetailController.h"

@interface PhotoViewController ()

@end

@implementation PhotoViewController {

    NSArray *array;

}

- (void)viewDidLoad {

        array = [[NSArray alloc]initWithObjects:@"walkerthumb.png",@"farmerthumb.png",@"unrulythumb.png",@"fetchthumb.png",@"walkerthumb.png",@"farmerthumb.png",@"unrulythumb.png",@"fetchthumb.png",@"walkerthumb.png",@"farmerthumb.png",@"unrulythumb.png",@"fetchthumb.png",@"walkerthumb.png",@"farmerthumb.png",@"unrulythumb.png",@"fetchthumb.png",@"walkerthumb.png",@"farmerthumb.png",@"unrulythumb.png",@"fetchthumb.png",@"walkerthumb.png",@"farmerthumb.png",@"unrulythumb.png",@"fetchthumb.png", nil];

    [super viewDidLoad];
    // Do any additional setup after loading the view.





}

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



    PhotoViewCell *cell = (PhotoViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];

    [[cell myImageView]setImage:[UIImage imageNamed:[array objectAtIndex:indexPath.item]]];

    return cell;





}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

    return [array count];


}

In my cell's header file, I have the image property called out like this: 在单元格的头文件中,我具有如下所示的image属性:

@property (weak, nonatomic) IBOutlet UIImageView *myImageView;

I'm trying to push a different detail view based on the image clicked. 我正在尝试根据单击的图像推送其他详细信息视图。 I understand it must involve some sort of array again, but I just don't know how to implement it. 我知道它必须再次涉及某种数组,但是我只是不知道如何实现它。 I don't know how to tell the Collection View what to do. 我不知道如何告诉“收藏夹视图”该怎么做。 None of the tutorials I have tried online have worked. 我在网上尝试过的所有教程都没有奏效。

You have to implement the following method to get the click of an item in collection view. 您必须实现以下方法才能在集合视图中单击某项。 - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath: (NSIndexPath *)indexPath { //indexPath will return the clicked row index and section. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {// indexPath将返回单击的行的索引和部分。 } }

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM