CNLiveMineAddInfoViewController.swift
4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//
// CNLiveMineAddInfoViewController.swift
// metaCode
//
// Created by open on 2023/6/7.
//
import Foundation
class CNLiveMineAddInfoViewController : CNLiveBaseViewController, UITableViewDelegate, UITableViewDataSource, UITableViewDragDelegate, UITableViewDropDelegate {
let kCNLiveMineInfoLListTableViewIdentifier = "kCNLiveMineInfoLListTableViewIdentifier"
lazy var tableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .plain)
tableView.delegate = self
tableView.dataSource = self
tableView.dragDelegate = self
tableView.dropDelegate = self
tableView.backgroundColor = HexColor("#F7F8FA")
tableView.tableFooterView = UIView.init()
tableView.rowHeight = 100
tableView.dragInteractionEnabled = true
tableView.contentInsetAdjustmentBehavior = .scrollableAxes
tableView.separatorStyle = .none
tableView.register(MineInfoLListTableViewCell.self, forCellReuseIdentifier: kCNLiveMineInfoLListTableViewIdentifier)
return tableView
}()
lazy var dataArray: NSMutableArray = {
let dataArray = NSMutableArray()
dataArray.add(["image":"mine_header_icon_defult_ava","name":"志愿者身份"])
dataArray.add(["image":"mine_header_icon_defult_ava","name":"退伍军人身份"])
return dataArray
}()
override func viewWillAppear(_ animated: Bool) {
navigationBarHidden = false
}
override func viewDidLoad() {
super.viewDidLoad()
titleName = "添加身份"
view.addSubview(tableView)
tableView.snp.makeConstraints { make in
make.top.equalTo(get_system_nav_height())
make.left.right.bottom.equalToSuperview()
}
}
private func dragCell(cell:UITableViewCell?) {
if #available(iOS 11.0, *) {
/// 当cell在拖拽过程中是否允许交互
cell?.userInteractionEnabledWhileDragging = false
} else {}
}
}
extension CNLiveMineAddInfoViewController {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveMineInfoLListTableViewIdentifier) as? MineInfoLListTableViewCell else{
return MineInfoLListTableViewCell()
}
let dict = dataArray[indexPath.row] as! Dictionary<String, Any>
cell.setupWithDataSource(icon: dict["image"] as! String, name: dict["name"] as! String)
dragCell(cell: cell)
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
func tableView(_ tableView: UITableView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
let item = UIDragItem(itemProvider: NSItemProvider(object: UIImage()))
return [item]
}
// MARK: UITableViewDropDelegate
func tableView(_ tableView: UITableView, performDropWith coordinator: UITableViewDropCoordinator) {}
func tableView(_ tableView: UITableView, dropSessionDidUpdate session: UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?) -> UITableViewDropProposal {
return UITableViewDropProposal(operation: .move, intent: .insertAtDestinationIndexPath)
}
func tableView(_ tableView: UITableView, canHandle session: UIDropSession) -> Bool {
// Only receive image data
return session.canLoadObjects(ofClass: UIImage.self)
}
//移动cell事件
func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath,
to destinationIndexPath: IndexPath) {
objc_sync_enter(self)
// let dict: Dictionary = dataArray[sourceIndexPath.row] as! Dictionary<String, Any>
// dataArray.remove(sourceIndexPath.row)
// if destinationIndexPath.row > dataArray.count {
// dataArray.append(dict)
// } else {
// dataArray.insert(dict, at: destinationIndexPath.row)
// }
objc_sync_exit(self)
// tableView.reloadData()
}
}