Is it possible to get the context menu to appear when performing a long press on the header and/or footer row? I've followed the instructions here (http://help.infragistics.com/iOS/2013.1/IGGridView_Enabling_Configuring_Context_Menus.html) but I can only get the menu to appear on the table cells.
Hi Daniel,
The built in mechanism for displaying a Context Menu is specifically tied to standard cells.
Now, this doesn't mean you can't display a context menu yourself. It just complicates the process slightly.
First, you'll want to create your own IGGridViewHeaderCell. Within that cell, you'll register a UILongPressGestureRecognizer. Then you have to implement to methods for the menu to work. "canBecomeFirstResponder" and "canPerformAction:withSender:". In the latter method you would return YES or NO based on the menu items you want to support.
@interface MenuHeader : IGGridViewHeaderCell@end
@implementation MenuHeader
-(id)init{ self = [super init]; if(self) { UILongPressGestureRecognizer* gesture = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)]; [self addGestureRecognizer:gesture]; } return self;}
-(BOOL)canBecomeFirstResponder{ return YES;}
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender{ return YES; // Only return YES for actions you want to support.}
-(void)longPress:(UILongPressGestureRecognizer*)gesture{ UIMenuController *menu = [UIMenuController sharedMenuController]; CGPoint location = [gesture locationInView:self]; [menu setTargetRect:CGRectMake(location.x, location.y, 10, 10) inView:self]; [self becomeFirstResponder]; [menu setMenuVisible:YES animated:YES];}
@end
Then all you have to do is just make sure your grid uses your custom header cell. If you are using the IGGridViewDataSource protocol, you would simply just make sure you're using your header cell. If you're using the IGGridViewDataSourceHelper, then you just need to derive from it and implement the "gridView:headerCellAt:" method and return an instance of your cell. .
@interface HeaderDSH : IGGridViewDataSourceHelper@end
@implementation HeaderDSH
-(IGGridViewHeaderCell *)gridView:(IGGridView *)gridView headerCellAt:(int)column{ MenuHeader* cell = [gridView dequeueReusableCellWithIdentifier:@"HEADER"]; if(cell == nil) { cell = [[MenuHeader alloc]initWithReuseIdentifier:@"HEADER"]; } cell.textLabel.text = [self gridView:gridView titleForHeaderInColumn:column]; return cell;}
-SteveZ