我正在慢慢地走出我的想法,試圖複製一個iPhone照片庫與集合視圖segueing到一個詳細信息視圖,我希望細節視圖有分頁就像照片庫確實。我到目前爲止的代碼似乎加載,但然後有錯誤。我有豁免斷點和斷點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
非常感謝您的任何幫助,您可以提供的是爲了我真的很感激。
你沒有說你正在得到哪個錯誤 – meda
我有豁免斷點和斷點1.1崩潰點是行self.imageView.image = img ;.這並沒有說明日誌上的錯誤,除了(lldb) – David