나의 발자취
FE] 당근마켓 아니고 양파마켓 만들기 (2) WIP 본문
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
}
'앱 개발 > iOS' 카테고리의 다른 글
[SwiftUI] OpenAPI 활용한 Book Finder App 만들기 (0) | 2024.11.08 |
---|---|
[SwiftUI-UIKit] 같이 사용하기 (0) | 2024.11.07 |
[FE] 당근마켓 아니고 양파마켓 만들기 (!!!!!!WIP!!!!!!!) (0) | 2024.11.06 |
[UIKit] Alamofire, Azure AI Translate API 이용해서 간단 번역 기능 앱 만들기 (2) (3) | 2024.11.05 |
[UIKit] Alamofire, Azure AI Translate API 이용해서 간단 번역 기능 앱 만들기 (1) (0) | 2024.11.05 |
Comments