Идентификатор Segue на раскадровке iPad
У меня есть приложение, настроенное для просмотра коллекций, в котором есть несколько ячеек, затем происходит переход к другому с полноэкранной ячейкой для воссоздания фотогалереи. У меня это нормально работает на iPhone, но когда я пытаюсь на iPad, нажатие на первую ячейку должно распознать элемент по пути индекса и передать его в полноэкранный режим, чего не происходит.
Я считаю, что причина в том, что я ищу идентификатор сегмента, и, поскольку это универсальное приложение, я использую один и тот же код для обоих целей. На раскадровке iPhone я могу установить идентификатор сегмента, но он не отображается в раскадровке 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 ответа
Если вы используете ту же раскадровку, что и в iPhone с iPad, то вы можете просто скопировать содержимое раскадровки iPhone и вставить в него раскадровку iPad. Вещи будут неуместны, но если использовать автоматическое расположение, это будет исправлено во время выполнения. Или вы могли бы следовать этому
Только что видел, что вы сказали "не появляется в раскадровке iPad".
Это не просто появится, если вы не настроите это самостоятельно.
Вам нужно будет зайти в файл раскадровки iPad и снова установить идентификатор сегмента.