You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
4.4 KiB
137 lines
4.4 KiB
![]()
2 years ago
|
//
|
||
|
// TelephoneBookViewController.swift
|
||
|
// Lookfit
|
||
|
//
|
||
|
// Created by ecell on 2022/8/25.
|
||
|
// Copyright © 2022 Sheldon. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import UIKit
|
||
|
import Contacts
|
||
|
|
||
|
|
||
|
class TelephoneBookViewController: ViewController {
|
||
|
|
||
|
|
||
|
var items:[String] = []
|
||
|
var seleteArr:NSMutableArray = []
|
||
|
|
||
|
var tableView:UITableView?
|
||
|
|
||
|
override func loadView() {
|
||
|
super.loadView()
|
||
|
}
|
||
|
override func makeUI() {
|
||
|
super.makeUI()
|
||
|
let rightItem = UIBarButtonItem.baseBarButtonItem(normalImg: "", highImg: nil, title: MultiLanguageKey.save.localized, target: self, action: #selector(clickSave))
|
||
|
navigationItem.rightBarButtonItem = rightItem
|
||
|
|
||
|
}
|
||
|
|
||
|
override func viewDidLoad() {
|
||
|
super.viewDidLoad()
|
||
|
self.monitor()
|
||
|
|
||
|
//创建表视图
|
||
|
self.tableView = UITableView(frame: self.view.frame, style:UITableView.Style.plain)
|
||
|
self.tableView!.delegate = self
|
||
|
self.tableView!.dataSource = self
|
||
|
self.tableView!.register(UITableViewCell.self, forCellReuseIdentifier: "SwiftCell")
|
||
|
//设置允许单元格多选
|
||
|
self.tableView!.allowsMultipleSelection = true
|
||
|
self.view.addSubview(self.tableView!)
|
||
|
|
||
|
|
||
|
items = BluetoothTool.contactPeploe() as! [String]
|
||
|
//print(items as Any)
|
||
|
self.tableView!.reloadData()
|
||
|
}
|
||
|
|
||
|
@objc func clickSave() {
|
||
|
if (self.seleteArr.count != 0) {
|
||
|
SVProgressHUD.show()
|
||
|
BluetoothService.shared.syncContactWithBleCmdType(seleteArr: self.seleteArr)
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
SVProgressHUD.showError(withStatus: MultiLanguageKey.selectNoPhone.localized)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func monitor() {
|
||
|
/// 指令成功失败监听
|
||
|
Observable.of(kNotificationCenter.rx.notification(Notification.Name(rawValue: CmdSuccess)),
|
||
|
kNotificationCenter.rx.notification(Notification.Name(rawValue: CmdTimeout)))
|
||
|
.merge()
|
||
|
.subscribe(onNext: { [weak self] notification in
|
||
|
guard let `self` = self, let cmd = notification.object as? BleCMD else { return }
|
||
|
let isSuccess = notification.name.rawValue == CmdSuccess
|
||
|
switch cmd {
|
||
|
case .syncContact:
|
||
|
if isSuccess {
|
||
|
SVProgressHUD.showSuccess(withStatus: MultiLanguageKey.syncDataSucceed.localized)
|
||
|
self.navigationController?.popViewController(animated: true)
|
||
|
return
|
||
|
}
|
||
|
SVProgressHUD.showSuccess(withStatus: MultiLanguageKey.setFail.localized)
|
||
|
default: break
|
||
|
}
|
||
|
})
|
||
|
.disposed(by: rx.disposeBag)
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
extension TelephoneBookViewController: UITableViewDelegate {
|
||
|
// 选中
|
||
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||
|
let cell = self.tableView?.cellForRow(at: indexPath)
|
||
|
cell?.accessoryType = .checkmark
|
||
|
self.seleteArr.addObjects(from: [self.items[indexPath.row]])
|
||
|
NSLog("选中%@",self.seleteArr)
|
||
|
}
|
||
|
|
||
|
// 取消选中
|
||
|
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
|
||
|
let cell = self.tableView?.cellForRow(at: indexPath)
|
||
|
cell?.accessoryType = .none
|
||
|
self.seleteArr.removeObjects(in: [self.items[indexPath.row]])
|
||
|
NSLog("取消%@",self.seleteArr)
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
extension TelephoneBookViewController: UITableViewDataSource {
|
||
|
|
||
|
func numberOfSections(in tableView: UITableView) -> Int {
|
||
|
|
||
|
return 1
|
||
|
|
||
|
}
|
||
|
|
||
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||
|
|
||
|
return items.count
|
||
|
|
||
|
}
|
||
|
|
||
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||
|
|
||
|
let identify:String = "SwiftCell"
|
||
|
let cell = tableView.dequeueReusableCell(withIdentifier: identify, for: indexPath)
|
||
|
cell.selectionStyle = UITableViewCell.SelectionStyle.none
|
||
|
cell.textLabel?.numberOfLines = 0;
|
||
|
cell.textLabel?.text = self.items[indexPath.row]
|
||
|
// 标记对勾的颜色
|
||
|
// cell.tintColor = UIColor.brown
|
||
|
if let _ = tableView.indexPathsForSelectedRows?.firstIndex(of: indexPath){
|
||
|
cell.accessoryType = .checkmark
|
||
|
} else {
|
||
|
cell.accessoryType = .none
|
||
|
}
|
||
|
|
||
|
return cell
|
||
|
}
|
||
|
|
||
|
}
|