Wallpaper_Home/wallpaper_project/wallpaper_project/Ranking/C/WA_RankingVC.swift
2024-04-22 10:40:00 +08:00

85 lines
2.4 KiB
Swift

//
// WA_RankingVC.swift
// wallpaper_project
//
// Created by 16 on 2024/3/27.
//
import UIKit
import FirebaseAnalytics
import FirebaseCore
class WA_RankingVC: WA_RootVC {
@IBOutlet weak var tableView: UITableView!
var MKArr = [WA_RakModel]()
override func viewDidLoad() {
super.viewDidLoad()
setNetwork()
settableView()
// setNetwork()
}
func settableView(){
tableView.delegate = self
tableView.dataSource = self
tableView.register(UINib(nibName: "WA_RakingCell", bundle: nil), forCellReuseIdentifier: "WA_RakingCell")
}
func setNetwork(){
if let path = Bundle.main.path(forResource: "rankJson", ofType: "json"),
let jsonData = try? Data(contentsOf: URL(fileURLWithPath: path)),
let rkModels = try? JSONDecoder().decode([WA_RakModel].self, from: jsonData) {
MKArr = rkModels
} else {
print("Failed to read or parse JSON file.")
}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBar.isHidden = true
}
@IBAction func addBtn(_ sender: Any) {
Analytics.logEvent("goin_release", parameters: nil)
if isLoggedIn(){
let vc = WA_AddVC()
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: true)
}else{
let vc = WA_LoginVC()
self.navigationController?.pushViewController(vc, animated: true)
}
}
}
extension WA_RankingVC:UITableViewDelegate,UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return MKArr.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "WA_RakingCell", for: indexPath)as!WA_RakingCell
cell.model = MKArr[indexPath.row]
cell.shView.isHidden = true
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let vc = WA_RKDetailsVC()
vc.model = MKArr[indexPath.row]
self.navigationController?.pushViewController(vc, animated: true)
}
}