【发布时间】:2014-11-09 20:01:09
【问题描述】:
我在两个不同的情况下遇到了类似的问题,但我觉得解决一个问题会解决另一个问题。我是菜鸟。我正在使用一个收藏视图来填充一个 NSArray 的照片库。集合视图工作得很好,并以正确的顺序填充正确的图像。我只是不知道如何让详细视图与我专门拥有的代码一起正常工作。我在 .h 文件中设置了我的代表:
@interface PhotoViewController : UICollectionViewController <UICollectionViewDelegate, UICollectionViewDataSource>
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];
}
在我的单元格的头文件中,我有这样的图像属性:
@property (weak, nonatomic) IBOutlet UIImageView *myImageView;
我正在尝试根据单击的图像推送不同的详细信息视图。我知道它必须再次涉及某种数组,但我只是不知道如何实现它。我不知道如何告诉 Collection View 该怎么做。我在网上尝试过的教程都没有奏效。
【问题讨论】:
-
你能展示你的
didSelectItemAtIndexPath方法吗? -
我没有那个。我是不是该?我基本上只有我发布的内容,其中有 cellForItemAtIndexPath。
-
这是当用户选择(点击)您的一个集合视图单元格时调用的委托方法 - 所以这通常是您用来移动到详细视图的方法。
-
好的,谢谢,我得研究一下如何实现它,但这为我指明了正确的方向。
标签: ios iphone nsarray uicollectionview uicollectionviewcell