Передать indexpath collectionview (popover) в основной viewController
Здравствуйте!
Есть ViewController
, в нем есть navigationbar
с кнопкой, при нажатии которой открывается popover
, внутри которого collectionview с элементами.
В классе PopoverCollectionViewController
настраиваю collectionview
:
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 45;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"Cell";
CollectionViewCell *cell = (CollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
int imageNumber = indexPath.row % 45;
cell.imageView.image = [UIImage imageNamed:[[NSString stringWithFormat:@"image%d", indexPath.row] stringByAppendingString:@".png"]];
if (cell.selected) {
cell.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:153/255.0 alpha:1]; // highlight selection
}
else
{
cell.backgroundColor = [UIColor clearColor]; // Default color
}
self.collectionView.allowsMultipleSelection = YES;
[super setEditing:YES animated:YES];
return cell;
}
Этот popover вызывается в классе editSchemeViewController по ibaction при нажатии этой кнопки след. методом:
- (IBAction)actionButtonPressed:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UICollectionViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"Popover"];
self.popover = [[UIPopoverController alloc] initWithContentViewController:viewController];
[self.popover presentPopoverFromBarButtonItem:self.actionButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[self.popover setPopoverContentSize:CGSizeMake(320, 440)];
}
Нужно передать из класса PopoverCollectionViewController
indexPath.item
выбранных элементов в класс editSchemeViewController
, чтобы в нем сразу же отобразить выбранные элементы, хотелось бы так, кликнул на элемент в collectionView
, который в popover, элемент сразу отображался на основном виде приложения, из которого вызывается popover.
Подскажите, как это реализовать, желательно на примере.
Источник: Stack Overflow на русском