iPhone照片库应用程序需要帮助,请



我是新的集合视图,想知道这是否是创建它们的最佳方式,我也想从那里segue到一个启用分页的详细视图的一些建议。

#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

是另一个用于详细视图的集合视图,或者是启用了分页的滚动视图,因为我不确定如何实现这一点?我还想在顶部导航栏上有一个标题?

提前感谢!

我可以在你的代码中找到一些编码错误。这将导致错误。marbleImages是一个带有字符串对象

的数组。
marbleImages = [NSArray arrayWithObjects:@"arabescato.jpg",...];

但是在prepareForSegue:中,你做的是

destViewController.recipeImageName = [marbleImages[indexPath.section] objectAtIndex:indexPath.row]; 

这段代码需要一个数组对象的数组。以上代码可以转换为

 NSString *obj = [marbleImages[indexPath.section]] // It will return string only since you are storing string
[obj objectAtIndex:indexPath.row]// This will cause error since NSString does not have a method objectAtIndex:  

我希望你只有一个节(我没有找到noOfSections方法)。所以请输入

    destViewController.recipeImageName = [marbleImages objectAtIndex:indexPath.row];

关于详细视图的建议

我认为你试图模仿iphone原生照片应用程序。为了获得相同的感觉,你应该使用滚动视图与分页启用,甚至可能与收集视图也。一个简单的实现是使用集合视图。如果你调整CollectionViewFlowLayout的属性,你可以实现这个。

最新更新