UA-17470720-3

Jump to content


Photo
- - - - -

AccessoryButtonTapped not getting called


  • Please log in to reply
2 replies to this topic

#1 sebaro1989

sebaro1989

    Jr. Member

  • STV Lite
  • PipPip
  • 17 posts
Reputation: 4
Good

Posted 20 April 2016 - 05:58 AM

Hi, i´m currently trying to add a custom accessory view to a SCPropertyTypeNumericTextField and the problem that i´m having is that as soon as I try to set a different view to that accessory view the delegate AccessoryButtonTapped stops getting called. (Also if i leave the accessory view as default a  (i) button appears)

 

This is my current code:

 

 SCNumericTextFieldAttributes* numPerPlantAttrs = [SCNumericTextFieldAttributes attributesWithPlaceholder:@"Per Plant"];
    SCPropertyDefinition *numberPerPlantDefinition = [entity propertyDefinitionWithName:@"numberPerPlant"];
    numberPerPlantDefinition.type = SCPropertyTypeNumericTextField;
    numberPerPlantDefinition.attributes = numPerPlantAttrs;
    numberPerPlantDefinition.cellActions.willConfigure = ^(SCTableViewCell *cell, NSIndexPath *indexPath) {
        SCNumericTextFieldCell *sizeCell = ((SCNumericTextFieldCell *)cell);
        sizeCell.displayZeroAsBlank = YES;
        sizeCell.textField.textAlignment = NSTextAlignmentRight;
        sizeCell.textField.accessibilityLabel = @"Number Per Plant";
        
        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        
        UIImage *greenDisclosure = [UIImage imageNamed:@"green_disclosure_button.png"];
        CGRect frame = CGRectMake(44.0, 44.0, greenDisclosure.size.width, greenDisclosure.size.height);
        button.frame = frame;
        [button setBackgroundImage:greenDisclosure forState:UIControlStateNormal];
        button.userInteractionEnabled = YES;
        button.backgroundColor = [UIColor clearColor];
        
        sizeCell.accessoryView = button;
        sizeCell.accessoryView.userInteractionEnabled = YES;
        
//        UIView *view =[[UIView alloc] initWithFrame:CGRectMake(0., 0., 33., 33.)];
//        view.backgroundColor = [UIColor redColor];
//        cell.accessoryView = view;
    };
    
    numberPerPlantDefinition.cellActions.accessoryButtonTapped = ^(SCTableViewCell *cell, NSIndexPath *indexPath) {
        ObservedPest *op = (ObservedPest*)[cell boundObject];

 

 

I also checked this post:

http://sensiblecocoa...orybuttontapped

 

But it did´t seemed to work.

 

Thanks in advance!

Regards,

Sebastian Vazquez

 



#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 21 April 2016 - 06:37 AM

Hi Sebaro,

 

When you install your own custom button, you become the one responsible for setting its 'target' and 'action' properties, just like any other button you use elsewhere in your app. The 'accessoryButtonTapped' action only gets called for the default cell accessory provided by iOS.

 

Hope this helps.



#3 sebaro1989

sebaro1989

    Jr. Member

  • STV Lite
  • PipPip
  • 17 posts
Reputation: 4
Good

Posted 21 April 2016 - 07:52 AM

Tarek and Ozie, thanks for your feedback, I ended up managing the action the usual way as you suggested.

 






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users