UIStepper not being able to register tapping.

I have a UIStepper object added to a custom tableviewcell. There is a label below it on the cell too. I need the label to display value changes, in accordance with the manipulation done through the UIStepper. The problem I facing though is that when i run the project and the interface displays on the simulator, I'm unable to make stepper register taps when i click on the "plus" or the "minus" button. Even the related IBAction does not log into the console. I have not hooked all the objects to their appropriate ivars in the interface file properly. I have tried diagnosing the problem. But it was to no avail. Kindly advise, anyone.

Here is the IBAction code:-

- (IBAction)changeItemValueWith:(UIStepper *)sender {
    NSLog(@"%@",NSStringFromSelector(_cmd));
    NSString *selectorString= NSStringFromSelector(_cmd);
    selectorString= [selectorString stringByAppendingString:@"havingValue:"];
    SEL selector= NSSelectorFromString(selectorString);
    [self sendAction:selector withObject:sender withObject:valueLabel toController:controller];
}


I can provide with more details of the interface settings.

Accepted Reply

Could you add a textfield in the cell, just to see if it reacts to clicks ?

Replies

So, you mean

NSLog(@"%@",NSStringFromSelector(_cmd));

does not log anything ?


Have you connected the stepper from IB to the IBAction ?

Try to do a clean Build Folder (option clean in Product menu).


What event did you connect to the IBAction ? You should connect to valueChanged.


I've checked this set up works correctly (in XCode 9.3, in Swift).

I included a stepper in the custom cell xib.


I connected the stepper to IBAction in UITableViewCell custom class


class CustomCell: UITableViewCell {

// Other code for CustomCell
    @IBAction func step(_ sender: Any) {
        print("changed")
    }


}

Yeah, i have the connection set up properly and yes, NSLog in the IBAction does not log to the console. The event for the connection is "valueChanged". I have a label below the stepper too. Do you think that somehow the label is overlaying the stepper which is keeping the latter from getting any taps?

Yes, need to check the label is not "overlapping" the Stepper, but that seems unlikely.


What other objects have you defined in the xib ?

Have you checked (in IB Attributes inspector) for the UIStepper that control is enabled ?


Remove the connection (in Connections Inspector) for value changed

clean Build folder (option clean in Product menu)

recreate the connection

This sort of thing could be caused by 1) incorrect IBAction setup, 2) userInteractionEnabled = false on the view or any superview, 3) some other view in front absorbing touches, or 4) view is drawn outside the bounds of a superview whose clipsToBounds is false (the default). The runtime view debugger can probably help with most of those.

Yes, the stepper control is 'enabled'. It was check-marked from the beginning.

This is what my interface looks like in xib file:-

https://www.dropbox.com/s/88kteya6rpzhz5h/Screen%20Shot%202018-05-20%20at%208.48.50%20PM.png?dl=0


In runtime, the label is overlaying the stepper even though i tried adjusting the constraints in the size inspector. Here is what it looks like in runtime:-

https://www.dropbox.com/s/z7m1fz9jq6ye1o1/Screen%20Shot%202018-05-20%20at%208.52.41%20PM.png?dl=0

The "userInteractionEnabled" has remained 'checked' in the attributes inspector throughout the whole time. As far as clipsToBounds is concerned, I did check for this in the "ContentView" of the custom cell. I believe that this is the super-view for all the visual elements within the cell. The property was pre-checked in the attributes inspector. I'd want you to have a look at these links:-

1.) Interface in the XIB file- https://www.dropbox.com/s/88kteya6rpzhz5h/Screen%20Shot%202018-05-20%20at%208.48.50%20PM.png?dl=0

2.) Interface during runtime in iPad simulator- https://www.dropbox.com/s/z7m1fz9jq6ye1o1/Screen%20Shot%202018-05-20%20at%208.52.41%20PM.png?dl=0


I've been doing some tinkering inside the size inspector for size constraints for each element, including the stepper, but haven't reached anywhere.

On the images, looks like the height you have reserved for the custom cell is not enough for the nib.


And the label is hiding the stepper.


Here is how I handled it in an app, in the viewDidLoad of the ViewController homing the tableView


    override func viewDidLoad() {
        super.viewDidLoad()

        tableView.register(CustomCell.self, forCellReuseIdentifier: "SignalisationCell")  
        let nib = UINib(nibName: "CustomCell", bundle: nil)
        tableView.register(nib, forCellReuseIdentifier: "SignalisationCell")
      
        tableView.estimatedRowHeight = 75.0     // Adapt for your custom cell
        tableView.rowHeight = UITableViewAutomaticDimension

I resized all the objects inside the content view and changed the size of the custom cell as well.

In the xib file: https://www.dropbox.com/s/8jh6omvgcyabfgk/Screen%20Shot%202018-05-23%20at%2011.34.53%20PM.png?dl=0

In runtime:- https://www.dropbox.com/s/3fns266k92bf4lz/Screen%20Shot%202018-05-23%20at%2011.36.23%20PM.png?dl=0


Earlier the value label had been somewhat covering the stepper. This time around, I shrunk its size so much so that its not even touching the stepper. But as you can see in the runtime screenshot, it still is overlaying the stepper somewhat. Do you think that its absorbing the taps meant for the stepper? But if i click on the upper part of the stepper, which by my estimation shouldn't be overlapped with the label below, it still doesn't register the taps on the 'plus' or 'minus' segment of the stepper.

Could you add a textfield in the cell, just to see if it reacts to clicks ?

I added a new button above the label and had it superimposed over the stepper. Added a corresponding action to test the button. Ran the project. Clicked on the new button and it did react to the click. The corresponding IBAction did log into the console. So it turned out that the label wasn't absorbing the touches this one time. Then, I deleted it and then deleted the underlying the stepper also. Added a new stepper, positioned it like the one before. Reconnected the older IBAction (changeValueWith:) to it. It worked this time. I clicked the stepper and the changes started registering in the console and the valueLabel showed the changes too. Thanx for the assist. It really helped. Cannot thank u enough.

GREAT. Sometimes, the best is to remove and rebuild.


Good continuation.