UA-17470720-3

Jump to content


Photo
- - - - -

enable menus in table views?


  • Please log in to reply
4 replies to this topic

#1 Don Metzler

Don Metzler

    Starting Out

  • STV 3.0 Pro
  • Pip
  • 2 posts
Reputation: 1
Good

Posted 03 February 2012 - 04:18 AM

How can I use the UITableViewDelegate callbacks to enable menus when using the Sensible TableView classes?

- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath;
- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender;
- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender;

I have tried setting my UITableView delegate but the above methods never get called. Are there comparable methods for SCTableViewModelDelegate?

Thanks,
Don

#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 04 February 2012 - 03:15 PM

Hi Don and welcome to our forums! :)

We're adding all these new iOS 5 specific methods to SCTableViewModelDelegate in STV 3.0. If you need this urgently, please tell me and I'll prepare you a patch for v2.2.0. Thanks!

#3 Don Metzler

Don Metzler

    Starting Out

  • STV 3.0 Pro
  • Pip
  • 2 posts
Reputation: 1
Good

Posted 04 February 2012 - 08:31 PM

Thank you for the quick reply. Great product by the way!

When it STV 3.0 coming out?

Thanks,
Don

#4 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 539 posts
  • LocationIreland
Reputation: 134
Popular

Posted 28 October 2015 - 01:10 AM

Hi all,

 

I know I'm resurrecting a very old thread but did any of these methods make it into STV 5.x? I can't find anything relevant in the documentation.

 

I'm having problems getting an UIMenuController to show up from a UILongPressGestureRecognizer on a SCCustomCell. I can get the UILongPressGestureRecognizer action to fire, but canBecomeFirstResponder and canPerformAction:withSender: are never called in my SCCusotmCell subclass. Is it that the default NO of tableView:shouldShowMenuForRowAtIndexPath: is stopping the UIMenuController showing? Anyone got this working? Any pointers?


Cheers,

Dave

www.dgapps.ie

#5 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 539 posts
  • LocationIreland
Reputation: 134
Popular

Posted 30 October 2015 - 12:05 AM

So I checked STV 5.x code and the UITableViewDelegate methods 

 

- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath;
- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender;
- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender;

 

aren't implemented :-(

 

 

Building my own version of STV 5.1.3 with those methods implemented, with shouldShowMenuForRowAtIndexPath: returning YES and canPerformAction: returning NO, and then using this SCCustomCell subclass:

 



- (instancetype)initWithCoder:(NSCoder *)decoder {
    if (self = [super initWithCoder:decoder]) {

        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            UIMenuItem *menuItem = [[UIMenuItem alloc] initWithTitle:@"My Menu Item" action:@selector(myItemAction:)];

            [[UIMenuController sharedMenuController] setMenuItems:@[menuItem]];
            [[UIMenuController sharedMenuController] update];
        });
        
    }
    return self;
}


-(BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    if (action == @selector(myItemAction:)) {
        return YES;
    }
    // else
    return NO;
}

-(void) myItemAction:(id)sender {
    // do my action
}

 

looks to be working OK :-)

 

 

Tarek, can I request these UITableViewDelegate are implemented in STV, and there's some STV block magic to disable default menu items if required, and to add custom items, and to respond to default and custom menu items.


Cheers,

Dave

www.dgapps.ie




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users