我正在慢慢地想复制一个 iPhone 照片画廊,其中收藏视图与细节视图相结合,我希望细节视图像照片画廊一样具有分页功能。到目前为止,我的代码似乎已加载,但随后出现错误。我有豁免断点,断点 1.1 崩溃点是行 self.imageView.image = img;。除了(lldb)之外,这并没有说明日志上的错误。
我想知道我是否可以借用某人的天才来指出我哪里出错并纠正它?我还想为每个图像取一个标题到详细视图,但不知道如何/在哪里添加它。
我的代码是:
#import "MarbleCollectionViewController.h"
#import "DetailViewController.h"
@interface MarbleCollectionViewController () {
NSArray *marbleImages;
}
@end
@implementation MarbleCollectionViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
marbleImages = [NSArray arrayWithObjects:@"arabescato.jpg",
@"bianco-carrara.jpg",
@"botticino-classico2.jpg",
@"Calacatta_Oro.jpg",
@"crema-marfil-3.jpg",
@"crema-valencia.jpg",
@"emperador-dark.jpg",
@"jura-beige.jpg",
@"nero-marquina.jpg",
@"perlato-olympo.jpg",
@"rojo-alicante_marbleGRP1.jpg", nil];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return marbleImages.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
UIImageView *marbleImageView = (UIImageView *)[cell viewWithTag:100];
marbleImageView.image = [UIImage imageNamed:[marbleImages objectAtIndex:indexPath.row]];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"detailView" sender:collectionView];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"detailView"]) {
DetailViewController *destViewController = segue.destinationViewController;
NSIndexPath *indexPath = [[self.collectionView indexPathsForSelectedItems] objectAtIndex:0];
destViewController.img = [marbleImages objectAtIndex:indexPath.row];
[self.collectionView deselectItemAtIndexPath:indexPath animated:NO];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
详细视图是:
#import "DetailViewController.h"
@interface DetailViewController ()
@end
@implementation DetailViewController
@synthesize imageView, img;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.imageView.image = img;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
非常感谢您提供的任何帮助,我真的很感激。