Search code examples
iosswiftxcodeuibuttoncontainers

Xcode Swift buttons in second container don't work


I'm new in IOS programing. I'm facing a problem. There is a viewController and in this view controller there are 2 containers in my app. Both containers have buttons in it. All containers are hidden at the beginning. When a specific condition happened one of these containers appears. when the first container is shown, buttons in this container are working perfectly but if other container is shown, buttons in this container don't work. Buttons in this container appear but not functional. All these two containers are identical. I don't understand why second container's buttons don't work.

Any help would be greatly appreciated.

Some of my codes related to this problem are;

@IBOutlet weak var Snakky: UIInputView!
@IBOutlet weak var Kikko: UIInputView!


if(vmcType == 1)
        {
            Snakky.accessibilityActivate()
            
            Snakky.isHidden = false
           
            Kikko.isHidden = true
  
        }
        
        if(vmcType == 2)
        {
            Kikko.accessibilityActivate()
           
            Snakky.isHidden = true
            
            Kikko.isHidden = false

        }

 //One of my button function;

 @IBAction func bkey0(_ sender: Any) {

    keypadKeys += "0";
    print("Keypad=", keypadKeys)

    return
    
}

All button functions are same.

Containers class are UIInputViewController

Storyboard design picture

4x3 matrix keypad buttons work well at first container but -,+ buttons don't work at second container.

@valid sent me a link. I read it and add a class below. I assigned this class to Snakky and Kikko containers. By the way Snakky is a container with 4x3 buttons and Kikko is a container with 2 buttons(-,+). This is the touch test function. When Snakky is shown touch test prints "Touch" but when KiKko is shown touch test prints "No touch". Kikko's buttons is shown but unresponsive. Kikko and Snakky screen images are below.

Kikko screen image

Snakky screen image

class PassThroughView: UIView {

override func point(inside point: CGPoint, with event: UIEvent?) -> 
Bool {
        for subview in subviews as [UIView] {
            if !subview.isHidden && subview.alpha > 0 && 
subview.isUserInteractionEnabled && subview.point(inside: 
convert(point, to: subview), with: event) {
                print("Touch")
                return true
            }
        }
    print("No touch")
        return false
    }
}

Solution

  • I solved the problem. It is very strange situation. I added only height constraint to Kikko container and problem solved.