skip to Main Content

I’m trying to get the user interaction in iOS application, For example where user clicked, which button user clicked etc. is there is any way to capture these details in Xcode swift?

2

Answers


  1. You may do that like this:

    button.addTarget(self, action: #selector(onButtonClick(_:)), for: .touchUpInside)
    
    @objc
    func onButtonClick(_ sender: UIButton) {
        // you may get the detail by 'sender' object here
        sender.isSelected = !sender.isSelected
    }
    

    If you have multiply sender that invoke the same method, you can give them a tag for each. then you can detect which view invoke the event.

    if sender.tag == YOUR_TAG {
        // do sth.
    } else {
        // do sth. else
    }
    
    Login or Signup to reply.
  2. Better you can use tag values and tap gesture to identify the user interaction

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search