sure; hope it helps
Basic setup is:
Each section represent one instance of a "connection" (basically host information); one connection can contain several "units"; adressed via .item
The following functions contain quite some redundant code; I know I should put them in one method but that is more a style/cosmetic question.
This function actually try to store which "unit" got selected by the user
Code:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
FAHMAppDelegate *app = (FAHMAppDelegate *) [[UIApplication sharedApplication] delegate];
self.actionUnit = nil;
if (indexPath.section >= 0)
{
FAHMConnection *connection = [app.document.clientList objectAtIndex:indexPath.section];
FAHMUnit *unit = [connection.slotList objectAtIndex:indexPath.item];
self.actionUnit = unit;
}
}
similar function ... this one update the context menu with respect to one entry; the NSLog in here is actually the one I saw with the wrong information e.g. clicked on section 0, item 0 but get section 1, item 0.
Code:
- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath
{
FAHMAppDelegate *app = (FAHMAppDelegate *) [[UIApplication sharedApplication] delegate];
#if 1
NSLog(@"can show action for section %d, item %d ", indexPath.section, indexPath.item);
#endif
self.actionUnit = nil;
FAHMConnection *connection = nil;
FAHMUnit *unit = nil;
if (indexPath.section >= 0 && indexPath.section < [app.document.clientList count])
{
connection = [app.document.clientList objectAtIndex:indexPath.section];
unit = [connection getUnitAtIndex:indexPath.item];
self.slotProject.title = [NSString stringWithFormat:@"Project %@", unit.project.project ];
[[UIMenuController sharedMenuController] update];
}
return YES;
}
and the "decider code" for what entry in the menu should be shown
Code:
- (BOOL)collectionView:(UICollectionView *)collectionView
canPerformAction:(SEL)action
forItemAtIndexPath:(NSIndexPath *)indexPath
withSender:(id)sender
{
FAHMAppDelegate *app = (FAHMAppDelegate *) [[UIApplication sharedApplication] delegate];
#if 1
NSLog(@"can perform action for section %d, item %d ", indexPath.section, indexPath.item);
#endif
self.actionUnit = nil;
FAHMConnection *connection = nil;
FAHMUnit *unit = nil;
if (indexPath.section >= 0 && indexPath.section < [app.document.clientList count])
{
connection = [app.document.clientList objectAtIndex:indexPath.section];
unit = [connection getUnitAtIndex:indexPath.item];
}
if (action == @selector(pauseSlot:))
{
if (connection && unit)
{
if (!unit.unitIsDummy)
{
self.actionUnit = unit;
return YES;
}
}
}
....
Some guts feeling tells me it is a problem with the firstResponder; which one should it be: the collectionViewController or the collectionView ?
Code:
- (void)viewDidAppear:(BOOL)animated
{
...
NSLog(@"become first responder");
[self.collectionView becomeFirstResponder];
...
}
let me know if you need other snipplets.