Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ChristianVirtual

macrumors 601
Original poster
May 10, 2010
4,122
282
日本
I managed to get the UICollectionView running with UIMenuController. In many cases it works perfectly and I get the context menu for the item I selected.
But in 20% of the cases the item selected and where the menus shows up are be different ...

Like this case: I clicked on the top left item but the popup comes down left.

image.jpg

When looking into indexPath it even shows section 1, item 0; wrongly as I pressed section 0, item 0; can happen with all item.
Any idea what can be wrong ?
 
Last edited:

waterskier2007

macrumors 68000
Jun 19, 2007
1,871
228
Novi, MI
You're going to need to post some code for us to look at. I would think that the -didSelectItemAtIndexPath: method would be valuable to look at
 

ChristianVirtual

macrumors 601
Original poster
May 10, 2010
4,122
282
日本
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.
 

ChristianVirtual

macrumors 601
Original poster
May 10, 2010
4,122
282
日本
ok; I gave up on that one and implemented my own Popover view triggered by a long-tap-gesture ... that way I even have some nicer way to utilize the popover for other stuff. It works flawless (for what I see until now)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.