I would like to add actions to a button
in a toolbar
I added to a collectionView
.
The toolbar
has 4 share buttons but some reason, I'm not able to call the collectionView
items properly.
- (IBAction)share:(id)sender
{
NSIndexPath *newIndexPath = [NSIndexPath indexPathForItem:0 inSection:0];
[_collectionView insertItemsAtIndexPaths:@[newIndexPath]];
NSArray *selectedIndexPaths = [_collectionView indexPathsForSelectedItems];
NSMutableArray *selectedTexts = [NSMutableArray array];
for (NSIndexPath *indexPath in selectedIndexPaths) {
NSArray *section = videoArray[indexPath.section];
NSString *text = section[indexPath.row];
[selectedTexts addObject:text];
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:text];
[self presentViewController:tweetSheet animated:YES completion:nil];
NSLog(@"%@", text);
}
// NSLog(@"The share works fine");
}
This returns an error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (3) must be equal to the number of items contained in that section before the update (3), plus or minus the number of items inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'