UA-17470720-3

Jump to content


Photo
- - - - -

AccessoryButtonTapped not getting called


  • Please log in to reply
3 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 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 20 April 2016 - 11:29 PM

what you want to do is give the button a TAG and use this code.. you are overriding the accessoryView with your own.. the code "accessoryButtonTapped" only fires for inbuilt tableview disclosure buttons

 

// Objective-C
cellActions.customButtonTapped = ^(SCTableViewCell *cell, NSIndexPath *indexPath, UIButton *button)
{
    NSLog(@"Custom button with tag:%i has been tapped for cell at indexPath:%@.", button.tag, indexPath);
};

// Swift
cellActions.customButtonTapped =
{
    (cell, indexPath, button) in

    NSLog("Custom button with tag:%i has been tapped for cell at indexPath:%@.", button.tag, indexPath)
}

Edited by ozie, 20 April 2016 - 11:31 PM.

P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#3 sebaro1989

sebaro1989

    Jr. Member

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

Posted 21 April 2016 - 05:42 AM

Ozie, thanks for your help, I tried adding that cell action but its not getting called

 

 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";
        
        sizeCell.accessoryType = UITableViewCellAccessoryDetailButton;
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        
        UIImage *greenDisclosure = [UIImage imageNamed:@"green_disclosure_button.png"];
        CGRect frame = CGRectMake(0., 0., greenDisclosure.size.width, greenDisclosure.size.height);
        button.frame = frame;
        button.tag = 222;
        [button setBackgroundImage:greenDisclosure forState:UIControlStateNormal];
        button.userInteractionEnabled = YES;
        button.backgroundColor = [UIColor clearColor];
        
        sizeCell.accessoryView = button;
        sizeCell.accessoryView.userInteractionEnabled = YES;
        
    };
    
    numberPerPlantDefinition.cellActions.customButtonTapped = ^(SCTableViewCell *cell, NSIndexPath *indexPath, UIButton *button)
    {
        NSLog(@"Custom button with tag:%i has been tapped for cell at indexPath:%@.", button.tag, indexPath);
    };

 

 

Maybe I´m doing something wrong but I've tried with all the changes that i could think of, but it never seems to work.

 

Can you think of any other way to achieve this



#4 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 21 April 2016 - 06:39 AM

Please refer to: http://sensiblecocoa...led/#entry13379






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users