我设置了一个带有集合视图的应用程序,其中一个单元格上有一系列单元格,然后通过全屏幕单元格进行分割,以重新创建照片库。我在iPhone上工作正常,但是当我在iPad上试试时,点击第一个单元格应该识别索引路径上的项目并将其传递给全屏幕视图,这不会发生。
我相信原因是我正在寻找一个segue标识符,因为这是一个通用的应用程序我使用相同的代码进行两种用途。在iPhone故事板上,我可以设置segue标识符,但这不会出现在iPad故事板中。问题是…。这是正常的吗?有办法吗?我可以根据要求提供代码,但此时并不认为它与问题相关。
代码是:
第一次收藏视图
@implementation Study3CollectionViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self createData];
}
- (void)createData {
self.dresserImages = [NSMutableArray array];
[self.dresserImages addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Newton Wardrobes", @"name",
@"IMG_4723.JPG", @"image", nil]];
[self.dresserImages addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Newton Wardrobes", @"name",
@"IMG_4726.JPG", @"image", nil]];
[self.dresserImages addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Newton Wardrobes", @"name",
@"IMG_4729.JPG", @"image", nil]];
[self.dresserImages addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Newton Wardrobes", @"name",
@"IMG_4730.JPG", @"image", nil]];
[self.dresserImages addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Newton Wardrobes", @"name",
@"IMG_4731.JPG", @"image", nil]];
[self.collectionView reloadData];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.dresserImages.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
UIImageView *dresserImageView = (UIImageView *)[cell viewWithTag:100];
dresserImageView.image = [UIImage imageNamed:[[self.dresserImages objectAtIndex:indexPath.row] objectForKey:@"image"]];
return cell;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (_startingIndexPath) {
NSInteger currentIndex = floor((scrollView.contentOffset.x - scrollView.bounds.size.width / 1) / scrollView.bounds.size.width) + 1;
if (currentIndex < [self.dresserImages count]) {
self.title = self.dresserImages[currentIndex][@"name"];
}
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"collectionView"])
{
Study3DetailCollectionViewController *destViewController = (Study3DetailCollectionViewController *)segue.destinationViewController;
NSIndexPath *indexPath = [[self.collectionView indexPathsForSelectedItems] objectAtIndex:0];
destViewController.startingIndexPath = indexPath;
[destViewController.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
[self.collectionView deselectItemAtIndexPath:indexPath animated:NO];
}
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.collectionView scrollToItemAtIndexPath:self.startingIndexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
详情视图
@implementation Study3DetailCollectionViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self createData];
}
- (void)createData {
self.dresserImages = [NSMutableArray array];
[self.dresserImages addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Newton Wardrobes", @"name",
@"IMG_4723.JPG", @"image", nil]];
[self.dresserImages addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Newton Wardrobes", @"name",
@"IMG_4726.JPG", @"image", nil]];
[self.dresserImages addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Newton Wardrobes", @"name",
@"IMG_4729.JPG", @"image", nil]];
[self.dresserImages addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Newton Wardrobes", @"name",
@"IMG_4730.JPG", @"image", nil]];
[self.dresserImages addObject:[[NSMutableDictionary alloc]
initWithObjectsAndKeys:@"Newton Wardrobes", @"name",
@"IMG_4731.JPG", @"image", nil]];
[self.collectionView reloadData];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.dresserImages.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
UIImageView *dresserImageView = (UIImageView *)[cell viewWithTag:100];
dresserImageView.image = [UIImage imageNamed:[[self.dresserImages objectAtIndex:indexPath.row] objectForKey:@"image"]];
return cell;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (_startingIndexPath) {
NSInteger currentIndex = floor((scrollView.contentOffset.x - scrollView.bounds.size.width / 1) / scrollView.bounds.size.width) + 1;
if (currentIndex < [self.dresserImages count]) {
self.title = self.dresserImages[currentIndex][@"name"];
}
}
}
- (BOOL) shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout;
layout.itemSize = self.view.bounds.size;
[self.collectionView scrollToItemAtIndexPath:self.startingIndexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
答案 0 :(得分:0)
刚看到你说“没有出现在iPad故事板中”。
如果没有自己设置,它就不会出现。
您需要进入iPad故事板文件并再次设置segue标识符。
答案 1 :(得分:0)
如果您使用的是与iPad相同的故事板,那么您只需复制iPhone故事板的内容并将其粘贴到iPad故事板即可。事情会被错放,但如果使用自动布局,它将在运行时修复。或者您可以关注this