Blame view
App/createNew/VCNhapMucChup.swift
3.84 KB
|
d774f0637
|
1 |
import UIKit |
|
1341bf603
|
2 |
import GeneralUtils |
|
d774f0637
|
3 4 5 6 7 |
class VCNhapMucChup: UIViewController, IVCLoadDataTableViewUIThread {
@IBOutlet weak var edtTitle: UITextField!
@IBOutlet weak var topMargin: NSLayoutConstraint!
@IBOutlet weak var tableView: UITableViewLoadDataFromUIThread!
|
|
1341bf603
|
8 |
@IBOutlet weak var vTopLogo: VTopLogo! |
|
d774f0637
|
9 10 11 12 13 14 15 16 17 |
static func getInstance() -> VCNhapMucChup {
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vcOpen = storyboard.instantiateViewController(withIdentifier: "VCNhapMucChup") as! VCNhapMucChup
return vcOpen
}
override func viewDidLoad() {
super.viewDidLoad()
|
|
1341bf603
|
18 19 20 |
vTopLogo.leftBtnClick = {
self.btnLeftClick(self.vTopLogo)
}
|
|
d774f0637
|
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
tableView.emptyText = "Empty"
CellMucChupWithDelete.registerClass(tableView: tableView, forCellReuseIdentifier: "CellMucChupWithDelete")
self.tableView.separatorStyle = UITableViewCellSeparatorStyle.singleLine
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 150
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
tableView.initAndLoadData(self)
}
@IBAction func btnAddClick(_ sender: Any) {
if let title = edtTitle.text?.trimAndReturn(), title.length > 0 {
for item in tableView.itemsData {
|
|
1341bf603
|
36 |
if let mc = item as? ShootItem, mc.name == title {
|
|
d774f0637
|
37 38 39 40 |
CommonUtils.showToastLong(text: LocalizedString("muc_chup_da_ton_tai"))
return
}
}
|
|
1341bf603
|
41 |
tableView.itemsData.insert(ShootItem(name: title), at: 0) |
|
d774f0637
|
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
tableView.insertRows(at: [IndexPath(row: 0, section: 0)], with: .automatic)
tableView.removeAllLoaddingEmpty()
edtTitle.text = ""
} else {
CommonUtils.showToastLong(text: LocalizedString("khong_de_trong"))
}
}
@IBAction func btnRightClick(_ sender: Any) {
saveMucChup()
_ = getVcRoot()?.changeCurrentController(VCChonMucChup.getInstance())
}
@IBAction func btnLeftClick(_ sender: Any) {
saveMucChup()
_ = getVcRoot()?.changeCurrentController(VCNhapTenCtruong.getInstance())
}
private func saveMucChup() {
|
|
1341bf603
|
61 |
var mucChups = [ShootItem]() |
|
d774f0637
|
62 |
for item in tableView.itemsData {
|
|
1341bf603
|
63 |
if let mucChup = item as? ShootItem {
|
|
d774f0637
|
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
mucChups.append(mucChup)
}
}
getVcRoot()?.mucChups = mucChups
}
//region ============== TableView Data =========
func loadDataOnUI(complete: @escaping ([Any]?) -> ()) {
complete(getVcRoot()?.mucChups)
}
func getAllCell() -> [BaseCell] {
var baseCells: [BaseCell] = [BaseCell]();
baseCells.append(BaseCell(type: 0, identifier: "CellMucChupWithDelete"))
return baseCells
}
func getTypeOfData(baseobj: Any) -> Int {
return 0
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
1341bf603
|
86 |
if let mucChup = self.tableView.getItem(indexPath) as? ShootItem {
|
|
d774f0637
|
87 88 89 |
edtTitle.text = mucChup.name
}
}
|
|
1341bf603
|
90 |
func deleteMucChup(_ mucChupParam: ShootItem) {
|
|
d774f0637
|
91 92 93 |
var indexFind = -1, index = -1
for item in self.tableView.itemsData {
index += 1
|
|
1341bf603
|
94 |
if let mucChup = item as? ShootItem, mucChup.name == mucChupParam.name {
|
|
d774f0637
|
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
indexFind = index
break
}
}
if indexFind >= 0 {
tableView.itemsData.remove(at: indexFind)
tableView.deleteRows(at: [IndexPath(row: indexFind, section: 0)], with: .automatic)
}
}
//endregion
@IBAction func edtActionTrigerClick(_ sender: Any) {
edtTitle.endEditing(true)
}
func getVcRoot() -> VCRootCreateNew? {
return self.parent as? VCRootCreateNew
}
}
|