2014-01-06 10 views
0

애플 리케이션을 콜렉션 뷰로 설정 한 다음 일련의 셀을 누른 다음 다른 셀로 셀을 전환하여 전체 화면 셀로 사진 갤러리를 다시 만듭니다. 나는 아이폰에서 잘 작동하지만 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 
+2

두 스토리 보드에 식별자를 설정 했습니까? – Fogmeister

+0

예, 특히 prepareForSegues : sender :'part 코드를 제공해야합니다. – Raptor

+0

앱이 범용 앱인 경우 iPad 스토리 보드의 세그먼트 식별자를 별도로 설정해야합니다. –

답변

0

.

직접 설정하지 않고 표시됩니다.

iPad 스토리 보드 파일로 이동하여 Segue 식별자를 다시 설정해야합니다.

+0

다운 투표에 대한 특별한 이유가 있습니까? – Fogmeister

0

iPad 용 iPhone과 동일한 스토리 보드를 사용하는 경우 iPhone 스토리 보드의 내용을 복사하여 iPad 스토리 보드에 붙여 넣기 만하면됩니다. 상황이 잘못되었지만 자동 레이아웃을 사용하면 런타임에 수정됩니다. 아니면 따를 수 있습니다 this

관련 문제