让用户只按一次按钮

时间:2018-08-03 20:14:54

标签: ios swift button uibutton

我想让用户用一个按钮给+1或用另一个按钮给-1分,但是他们应该只能按一次这些按钮...

我使用此代码,但是用户仍然可以多次单击按钮...

D/customerobj: [
  <com.stripe.model.Card@148232829id=>JSON: {
    "address_city": null,
    "address_country": null,
    "address_line1": null,
    "address_line1_check": null,
    "address_line2": null,
    "address_state": null,
    "address_zip": "71000",
    "address_zip_check": "pass",
    "available_payout_methods": null,
    "brand": "Visa",
    "country": "US",
    "currency": null,
    "cvc_check": "pass",
    "default_for_currency": null,
    "description": null,
    "dynamic_last4": null,
    "exp_month": 4,
    "exp_year": 2021,
    "fingerprint": "EmNhHLSbWLElhMvG",
    "funding": "credit",
    "iin": null,
    "issuer": null,
    "last4": "4242",
    "name": null,
    "recipient": null,
    "status": null,
    "three_d_secure": null,
    "tokenization_method": null,
    "type": null,
    "account": null,
    "customer": "cus_DL2GSWX9bfTZeU",
    "id": "card_1CuMC8A41bIzZYFFlpiW3hZp",
    "metadata": {

    },
    "object": "card"
  }
]

1 个答案:

答案 0 :(得分:1)

由于发送者是UIButton,因此最好构造这样的函子

@IBAction func dislikeDidTouch(_ sender: UIButton)
@IBAction func likeDidTouch(_ sender: UIButton)

并在每个内部做

sender.isEnabled = false