class TableViewController: UITableViewController {
override func numberOfSections(in tableView: UITableView) -> Int {
return 20
}
override func tableView(_ tableView: UITableView,
numberOfRowsInSection section: Int) -> Int {
return 3
}
override func tableView(_ tableView: UITableView,
cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "basicStyleCell", for: indexPath)
tableView.rowHeight = 200
cell.textLabel!.text = "\(indexPath.section) , \(indexPath.row)"
return cell
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
tableView.sectionHeaderHeight = 10
tableView.backgroundColor = .systemGray6
return " "
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let alertController = UIAlertController(title: "어머나", message: "날 만졌어 \n Section \(indexPath.section) , Row \(indexPath.row)", preferredStyle: .alert)
let confirmAction = UIAlertAction(title: "그랬구나", style: .default, handler: nil)
alertController.addAction(confirmAction)
self.present(alertController, animated: false)
}
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 20
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
override func tableView(_ tableView: UITableView,
cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "basicStyleCell", for: indexPath)
tableView.rowHeight = 200
cell.textLabel!.text = "\(indexPath.section) , \(indexPath.row)"
return cell
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
tableView.sectionHeaderHeight = 10
tableView.backgroundColor = .systemGray6
return " "
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let alertController = UIAlertController(title: "어머나", message: "날 만졌어 \n Section \(indexPath.section) , Row \(indexPath.row)", preferredStyle: .alert)
let confirmAction = UIAlertAction(title: "그랬구나", style: .default, handler: nil)
alertController.addAction(confirmAction)
self.present(alertController, animated: false)
}
Bundle.main.path(forResource: 파일명, ofType: 파일타입, inDirectory: 파일경로(상위 폴더이름))
메소드를 이용하여 상수에 값을 넣어준다. -> 상수에 값을 넣어줄 때 옵셔널 바인딩
을 이용한다.try? String(contentsOfFile: )
메소드를 사용하여 JSON
내부의 값을 String
값으로 꺼내준다. 이 과정에서도 또한 옵셔널 바인딩
을 이용한다..data(using: .utf8)
메서드를 이용하여 String
값을 Data
타입으로 변경해주었습니다.JSONDecoder()
로 상수를 선언하고 그 상수를 이용하여 decoding
해준다.let decoder = JSONDecoder()
var itemList: [Item]?
itemList = try
do{
let itemList = decoder.decode([Item].self, from: data)
} catch{
print(error)
}
새시 (새로운 시작) 오좋 (오히려 좋아!)
윙빙과 짝이 되어서 좋다😎