ContactsViewController.swift 2.81 KB
//
//  ContactsViewController.swift
//  Twear
//
//  Created by yangbin on 2022/1/15.
//

import UIKit

class ContactsViewController: UIViewController {
    
    @IBOutlet weak var tableView: UITableView!
    @IBOutlet weak var noContactsView: UIView!
    
    var contacts: [ContactModel] = []

    override func viewDidLoad() {
        super.viewDidLoad()
        title = LocString("快捷通讯")
        
        let addButton = UIButton(frame: CGRect(x: 0, y: 0, width: 40, height: 28))
        addButton.setImage(UIImage(named: "device_add"), for: .normal)
        addButton.addTarget(self, action: #selector(add), for: .touchUpInside)
        navigationItem.rightBarButtonItem =  UIBarButtonItem(customView: addButton)
        
        
        tableView.register(UINib.init(nibName: "ContactCell", bundle: Bundle.main), forCellReuseIdentifier: "ContactCell")
        tableView.contentInset = UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 0)
        tableView.tableFooterView = UIView(frame: CGRect.zero)
        // Do any additional setup after loading the view.
    }
    
    @objc private func add() {
//        if alarmClockArray.count >= 5 {
//            MBProgressHUD.showh(LocString("您最多可设置5个闹钟"))
//            return
//        }
//        let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Setting", identifier: "EditAlarmClockVC")
//        navigationController?.pushViewController(vc, animated: true)
    }
    

    deinit {
        print("deinit\(NSStringFromClass(type(of: self)))!!!!!!!")
    }

}


extension ContactsViewController: UITableViewDelegate, UITableViewDataSource {

    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 50
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return contacts.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "ContactCell", for: indexPath) as! ContactCell
//        cell.alarmClock = alarmClockArray[indexPath.row]
//        cell.switchClosure = {[weak self] isOn in
//            self?.switchValueChanged(isOn, index: indexPath.row)
//        }
        return cell
    }
    

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
//        let cell = tableView.cellForRow(at: indexPath) as! SettingCell3
//        cell.isSelected = false
//        let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Setting", identifier: "EditAlarmClockVC") as! EditAlarmClockVC
//        vc.alarmClock = CurDevice.alarmClocks[indexPath.row]
//        vc.index = indexPath.row
//        vc.isEdit = true
//        navigationController?.pushViewController(vc, animated: true)
    }
}