애플 리케이션을 콜렉션 뷰로 설정 한 다음 일련의 셀을 누른 다음 다른 셀로 셀을 전환하여 전체 화면 셀로 사진 갤러리를 다시 만듭니다. 나는 아이폰에서 잘 작동하지만 iPad에서 첫 번째 셀을 클릭하면 인덱스 경로의 항목을 인식하고이를 전체 화면보기로 전달해야한다.iPad의 Segue 식별자 Storyboard
저는 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
두 스토리 보드에 식별자를 설정 했습니까? – Fogmeister
예, 특히 prepareForSegues : sender :'part 코드를 제공해야합니다. – Raptor
앱이 범용 앱인 경우 iPad 스토리 보드의 세그먼트 식별자를 별도로 설정해야합니다. –