TIL

26일차 TIL

h_luz 2024. 4. 2. 21:31

 

키오스크 팀 프로젝트

 

결제화면

이런 식으로 제작할 예정인데,

TableView로 하는 게 나을 것 같아서 그냥 테이블뷰로 하는 중!

 

TableView xib 커스텀 셀은

https://sunidev.github.io/ios/make-tableview-of-xib/

 

[iOS/Swift] xib로 TableView 만들기

이번 글은 xib로 간단한 TableView를 만드는 방법입니다. 첨부 이미지는 Storyboard intreface기반 Swift 프로젝트입니다.

sunidev.github.io

여기서 보고 했음

 

그리고 나는 결제화면이라서 모든 데이터를 받아올 수 있어야하기 때문에 AnyObject 에 담기로 했음

 

var things:[AnyObject] = []

이곳에 담긴 정보를 결제화면에 표시할 수 있도록 코드를 짜야하는데

난 정말 정말 정말 바보다.. ㅜㅠㅜ 어떻게 해야할 지 모르겠음..

 

그래도 어찌저찌 해보고, 시뮬레이터 돌려보려고 하는데 오류들이 날 가로막음... ㅠㅜㅠㅜㅠ

 

Build input file cannot be found: '/Users/t2023-m0005/Desktop/5SkinRabbins/Base.lproj/Main.storyboard'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it?

 

자꾸 내가 만든 PaymentStoryboard가 안 열리고 viewController에 메인 스토리보드를 열려고 함..

Is initial view controller 도 잘 체크해줬는데 . . . ㅠ

 

여튼 여기 사이트 보고 위에 오류는 해결했는데 그래도 시뮬레이터는 안 돌아간다..

검은 화면만 뜨길래 검색해봤더니 이 사이트에서

entry point가 삭제되었기 때문에 그렇다고 하는데 .. Is iniitial view controller 잘 체크되어있단 말임.. ㅠ?

 

이 사이트 보고 초기화 해봐도 안됨..

 

혹시나 해서 Is initial view controller를 main 스토리보드에 해주니까 흰 화면이 나오긴 했는데,, 왜 Is initial 바꿔도 안되는거지?!

 

결국 실패했다.. 우선 테이블 뷰 만든 코드만이라도 올려야지..

 

import UIKit

class PaymentViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
    
    @IBOutlet weak var tableView: UITableView!
    
    var things: [Any] = []
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return things.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "paymentCell", for: indexPath) as! PaymentTableViewCell
        
        if let thing = things[indexPath.row] as? IceCream {
            let thingImage = thing.englishName[indexPath.row]
            cell.payImageView.image = UIImage(named: thingImage.name)
            
            cell.payNameLabel.text = thing.koreanName
            
            let flavorText = thing.flavor[indexPath.row]
            cell.payDetailLabel.text = "\(flavorText.name), "
            
            cell.payPriceLabel.text = "\(thing.price)원"
        } else if let thing = things[indexPath.row] as? Coffee {
            cell.payImageView.image = UIImage()
            cell.payNameLabel.text = thing.name
            cell.payPriceLabel.text = "\(thing.price)원"
        } else if let thing = things[indexPath.row] as? Cake {
            cell.payNameLabel.text = thing.name
            cell.payPriceLabel.text = "\(thing.price)원"
        }
        //Beverage 나중에 추가
        return cell
    }
    
    override func viewDidLoad() {
        
        super.viewDidLoad()
        
        things.append(IceCream(koreanName: "파인트", englishName: [], choice: 3, flavor: [Flavor(name: "바닐라", image: UIImage()),Flavor(name: "아몬드봉봉", image: UIImage()),Flavor(name: "엄마는외계인", image: UIImage())], price: 452, image: UIImage(), isCorn: true))
        tableView.reloadData()
        
        tableView.delegate = self
        tableView.dataSource = self
        
        let nibName = UINib(nibName: "paymentCell", bundle: nil)
        tableView.register(nibName, forCellReuseIdentifier: "paymentCell")
        
        
    }

}

 

 

 

 

 

 

 

 

'TIL' 카테고리의 다른 글

28일차 TIL  (1) 2024.04.04
27일차 TIL  (3) 2024.04.03
25일차 TIL  (0) 2024.04.01
24일차 TIL  (2) 2024.03.29
23일차 TIL  (1) 2024.03.28