Masum Billah
Masum Billah

Reputation: 1093

Button click but not responding

I am new to iOS. Last two days I just tried to configure a button Click. I want to implement just onclick button in my swift5 project.

First Method:(Not working)

@IBOutlet weak var btnOutletFollowing       : UIButton!

@IBAction func followerBtn(_ sender: UIButton) {

        print("Button Clicked")

}

Second Method: Working

When I add this code, it's working fine.

override func viewDidLoad() {
    super.viewDidLoad()

    let button = UIButton(frame: CGRect(x: 0, y: 0, width: 200, height: 50))
    button.center = view.center
    button.backgroundColor = .black
    button.setTitle("iOSDevCenters Click", for: .normal)
    button.addTarget(self, action:#selector(self.buttonClicked), for: .touchUpInside)
    self.view.addSubview(button)

}
@objc func buttonClicked() {
    print("Button Clicked")
}

My question what's the possible problem with the first method?

Screensot of UI

Upvotes: 1

Views: 959

Answers (1)

Muhammad Ahmad
Muhammad Ahmad

Reputation: 259

enter image description here

Check If User Interaction in Enabled

Upvotes: 1

Related Questions