0
            for (index,phoneNum) in temp_arr_phoneNum.enumerated()
            {
               if temp_arr_msgType[index] == "3"
               {
                let btnimage : UIButton = UIButton()

                btnimage.setBackgroundImage(UIImage(named:"VideoIConDefault"), for: .normal)
                btnimage.tag = index
                btnimage.translatesAutoresizingMaskIntoConstraints = false
                btnimage.isUserInteractionEnabled = true
                containerView.addSubview(btnimage)
                btnimage.addTarget(self, action: 
                 #selector(self.tapDetected(_:)), for:UIControlEvents(rawValue: 0))
                arrayForBtnViews.append(btnimage)
               }
          }
       func tapDetected(_ sender: UIButton)
       {
       }

Only for the first button Action Target method is working......Other buttons are not performing clicked actions...(controlEvents,,, I tried for .touchUpInside also).....Button frames have been set through auto layout constraints programatically in other methods.

  • Is if temp_arr_msgType[index] == "3", true for multiple cases? What is the frame of containerView? Do containerView.clipsToBounds = true and check whether your other buttons are still visible. – Puneet Sharma Mar 01 '17 at 06:17
  • It is true for multiple cases,,,,ContainerView Frame is dynamically changed,,,It is inside scrollView... I am able to see Mutiple buttons on the screen. But action is working for first button only...I didnot use clipsToBounds = true.(it is unchecked in storyboard for containerview...Is it required? – Socraties Srikanth Mar 01 '17 at 06:24
  • If you want to make sure that the buttons can receive events, check the cliptosubviews property on containerView. This will clip all subviews(buttons in your case) where subview does not fit inside container frame. – Puneet Sharma Mar 01 '17 at 06:27
  • Checked to ClipsToBounds of ContainerView is giving InCorrect or Unexpected UI on Screen... – Socraties Srikanth Mar 01 '17 at 06:34
  • So, I guess you can see the problem now. Your UIButtons are out of bounds from your container view and hence they can not receive touch events. – Puneet Sharma Mar 01 '17 at 06:41
  • After clipToSubviews, can you still see the buttons? – Puneet Sharma Mar 01 '17 at 06:50
  • 1
    Thank You So much Puneet Sharma,, Yes You are correct. They are out of Container View.The problem is in the storyBoard, One constraint was wrong in Landscape mode. Now working fine... – Socraties Srikanth Mar 01 '17 at 06:53
  • Glad to help!!! – Puneet Sharma Mar 01 '17 at 06:59

0 Answers0