나의 발자취

FE] 당근마켓 아니고 양파마켓 만들기 (2) WIP 본문

앱 개발/iOS

FE] 당근마켓 아니고 양파마켓 만들기 (2) WIP

달모드 2024. 11. 7. 11:01

 

 

 

viewWillAppear()

    override func viewWillAppear(_ animated: Bool) {
        let endPoint = "\(host)/sales"
        guard let token = UserDefaults.standard.string(forKey: "token") else { return }
        let headers: HTTPHeaders = ["Authorization": "Bearer \(token)"]
        let alamo = AF.request(endPoint, method: .get, headers: headers)
        alamo.responseDecodable(of: ProductList.self) { response in
            switch response.result {
                case .success(let result):
                self.products = result.documents
                DispatchQueue.main.async {
                    self.tableView.reloadData()
                }
                case .failure(let error):
                    print(error.localizedDescription)
            }
        }
    }

 

 

 


 

셀 속성

 

 

cellForRowAt

 

이미지 url

글로벌에다가 

 

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
        guard let product = products?[indexPath.row] else { return cell }
        
        let imageView = cell.viewWithTag(1) as? UIImageView
        let lblName = cell.viewWithTag(2) as? UILabel
        let lblDescription = cell.viewWithTag(3) as? UILabel
        let lblUserName = cell.viewWithTag(4) as? UILabel
        let lblPrice = cell.viewWithTag(5) as? UILabel
        let imageURL = "\(storage)/\(product.photo)"
        if let url = URL(string: imageURL) {
            imageView?.kf.setImage(with: url)
        }
        // more to come
        

        return cell
    }

 

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
        guard let product = products?[indexPath.row] else { return cell }
        
        let imageView = cell.viewWithTag(1) as? UIImageView
        let lblName = cell.viewWithTag(2) as? UILabel
        let lblDescription = cell.viewWithTag(3) as? UILabel
        let lblUserName = cell.viewWithTag(4) as? UILabel
        let lblPrice = cell.viewWithTag(5) as? UILabel
        let imageURL = "\(storage)/\(product.photo)"
        if let url = URL(string: imageURL) {
            imageView?.kf.setImage(with: url)
        }
        lblName?.text = product.productName
        lblDescription?.text = product.description
        lblUserName?.text = product.userName
        lblPrice?.text = "\(product.price)"
    
        return cell
    }
Comments