Я для тренировки сделал галерею:
Я хочу организовать открытие изображения на полный экран при клике. Открытие само я уже сделал, однако у меня возникла проблема: в первый раз всегда открывается изображение под индексом 0, а в следующий раз то изображение, на которое я кликал до этого. Код выглядит так:
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
[collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionCenteredHorizontally];
selectedPhotoIndex = indexPath.row;
NSLog(@"%li", selectedPhotoIndex);
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"fullAttachShow"]){
DetailShowViewController *detailViewController = segue.destinationViewController;
detailViewController.fullImage = selectedPhotoIndex;
NSLog(@"%li", (long)detailViewController.fullImage);
}
}
Как я понял, у меня при клике вызывается метод: - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
и лишь потом: -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
И получается, что в следующие разы у меня открывается та картинка, которая должна была открыться до этого.
Как мне сделать, чтобы при клике сначала срабатывал -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
и лишь потом - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
?