gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 03:55:05 29 4
gpt4 key购买 nike

我是 Collection View 的新手,想知道这是否是创建它们的最佳方式,我还想了解一些关于从哪里转到启用分页的详细 View 的建议。

#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

这是我的详细 View 代码:

#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

是详细 View 的另一个 Collection View ,还是启用分页的 ScrollView ,因为我不确定如何实现这一点?我还希望能够在顶部导航栏上有一个标题?

提前致谢!

最佳答案

我可以在您的代码中发现一些编码错误。它会导致错误。 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];

详细 View 建议

我认为你正在尝试模仿 iPhone 的原生照片应用程序。为了获得同样的感觉,您应该使用启用分页的 ScrollView ,甚至也可以使用 Collection View 。一种简单的实现是使用 Collection View 。如果您调整 CollectionViewFlowLayout 的属性,您就可以实现这一点。

关于ios - iPhone 照片库应用程序需要帮助,请,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16607176/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com