问题描述
class ListVC: UIViewController {
var locationArr:[Locationzz]!
@IBOutlet weak var ListTV: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
willsOilListApiHitting()
self.ListTV.separatorStyle = .none
NotificationCenter.default.addObserver(self,selector: #selector(searchData),name:Notification.Name("search"),object: nil)
}
@objc func searchData (_ notification: NSNotification) {
if let name = notification.userInfo?["name"] as? String {
print(name)
}
}
extension ListVC:UITableViewDelegate,UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView,numberOfRowsInSection section: Int) -> Int {
if let data = self.locationArr,data.count > 0{
return locationArr.count
}else{
return 0
}
}
func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "WillisListViewTVCell",for: indexPath)as!WillisListViewTVCell
cell.nameLB.text = locationArr[indexPath.row].name
cell.tagLB.text = locationArr[indexPath.row].tag
let status = locationArr[indexPath.row].containerStatus
cell.selectionStyle = .none
if status == "1"{
cell.colorView.borderWidth = 1
cell.colorView.borderColor = UIColor.green
cell.colorView.cornerRadius = 10
}else if status == "2"{
cell.colorView.borderWidth = 1
cell.colorView.borderColor = UIColor.yellow
cell.colorView.cornerRadius = 10
}else{
cell.colorView.borderWidth = 1
cell.colorView.borderColor = UIColor.red
cell.colorView.cornerRadius = 10
}
return cell
}
func tableView(_ tableView: UITableView,heightForRowAt indexPath: IndexPath) -> CGFloat {
return 90
}
func tableView(_ tableView: UITableView,didSelectRowAt indexPath: IndexPath) {
print(indexPath.row)
let detailListVC = storyboard?.instantiateViewController(withIdentifier: "DetailListVC") as! DetailListVC
detailListVC.idVal = locationArr[indexPath.row].id
detailListVC.nameVal = locationArr[indexPath.row].name
navigationController?.pushViewController(detailListVC,animated: true)
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)