Reputation: 1093
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?
Upvotes: 1
Views: 959