当先锋百科网

首页 1 2 3 4 5 6 7

  值得注意的是 addTarget 中action 的参数,点击事件字符串后面要加 “:  ”

//
//  ViewController.swift
//  CBControler
//
//  Created by 黄涛 on 17/3/16.
//  Copyright © 2017年 huangtao. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var topLabel: UILabel!
    
    @IBOutlet weak var btnConnectDev: UIButton!
    
    @IBOutlet weak var btnAddDev: UIButton!
    
    @IBOutlet weak var btnEditDev: UIButton!
    
    @IBOutlet weak var btnDeleteDev: UIButton!
    
    func initButton(){
        btnConnectDev.tag = 2000;
        btnAddDev.tag = 2001;
        btnEditDev.tag = 2002;
        btnDeleteDev.tag = 2003;
        
        btnConnectDev.addTarget(self, action: "btnClickFun:", forControlEvents: UIControlEvents.TouchUpInside);
        
        btnAddDev.addTarget(self, action: "btnClickFun: