我是集合视图的新手,想知道这是否是创建它们的最佳方式,我还想获得一些关于从那里转到启用分页的详细视图的建议。
#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)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"detailView"]) {
DetailViewController *destViewController = segue.destinationViewController;
NSIndexPath *indexPath = [self.collectionView ];
destViewController.recipeImageName = [marbleImages[indexPath.section] 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 recipeImageView;
@synthesize recipeImageName;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.recipeImageView.image = [UIImage imageNamed:self.recipeImageName];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
是详细视图的另一个集合视图,还是启用分页的滚动视图,因为我不确定如何实现这一点?我也希望能够在顶部导航栏上有一个标题?
提前致谢!