👨‍🎓
Today I Learned
  • Today-I-Learend
  • 🍎WWDC
    • Developer Tools
      • Testing in Xcode
    • UIKit
      • UIDiffableDataSource
        • [WWDC 19] Advances in UI Data Sources
      • [WWDC2019] Advances in CollectionView Layout
  • 자료구조
    • Heap 자료구조
  • Clean code
    • 네이밍
    • 주석과 포맷팅
    • 함수
    • 클래스
    • 에러 핸들링
    • 가독성 높이기
    • 객체지향
  • Network
    • RestAPI
  • Swift
    • DateType
    • ARC
    • Availablity
    • KeyPath
    • Network
    • Never타입
    • Result
    • Selector
    • 검증함수
    • 메타타입
    • 동시성 프로그래밍
    • 메모리 안전
    • 에러처리
    • 접근제어 (Access Control)
    • 제네릭
    • 주요 프로토콜
  • 알고리즘
    • 그래프
    • 기초 알고리즘
    • 누적합(Prefix)
    • 복잡도
    • 비트마스킹
  • 운영체제
    • 운영체제의 개요
    • 프로세스와 스레드
    • CPU 스케줄링
    • 프로세스 동기화
    • 교착상태
    • 07. 메모리
    • 08.가상 메모리
    • 입출력 장치
    • 파일 시스템
  • UIKit
    • UITableView xib으로 만들어보기
  • 🖊️정보 기록
    • 코코아팟 배포하는 방법
  • iOS Project
    • 채팅 앱 만들기
      • Trouble shooting
      • 1. 디자인
      • 2. AutoLayout
    • 날씨 조회 어플리케이션
      • Figma를 이용한 UI 설계
      • TableView 연결하기
      • Networking
    • MVC -> MVVM으로 구조 변경해보기
      • MVC
      • MVVM
    • OAuth Project
      • 로컬 호스트를 이용한 로그인 페이지 제작
      • Github의 OAuth App 설정
    • Rest API 프로젝트
      • UI설계 (with Figma)
      • Network Model
      • MVVM 구조 전환
  • 🕶️UIKit
    • Compositional Layout
Powered by GitBook
On this page
  • TableView 설정방법
  • 1. TableView Cell 생성
  1. iOS Project
  2. 날씨 조회 어플리케이션

TableView 연결하기

주간 날씨를 보여주는 Table View를 만들어보자.

PreviousFigma를 이용한 UI 설계NextNetworking

Last updated 2 years ago

현재 뷰 상태

TableView 설정방법

1. TableView Cell 생성

(Cocoa Touch Class를 이용해서 생성하며, xib도 같이 생성하자.

class file과 xib 파일 outlet 연결

import UIKit

class WeaklyWeatherTableViewCell: UITableViewCell {

    @IBOutlet weak var weatherIconImageView: UIImageView!
    @IBOutlet weak var dateLabel: UILabel!
    @IBOutlet weak var weatherLabel: UILabel!
    @IBOutlet weak var maximumTeperatureLabel: UILabel!
    @IBOutlet weak var minimumTemperatureLabel: UILabel!
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}

xib의 Attribute Controller에서 id 설정

Tableview datasource, delegate 설정

import UIKit

class ViewController: UIViewController {
    
    // delegate, datasource 설정
    @IBOutlet weak var weaklyWeatherTableView: UITableView! {
        didSet {
            weaklyWeatherTableView.dataSource = self
            weaklyWeatherTableView.delegate = self
        }
    }
    
    let weatherData = ["16", "24", "17", "34", "16", "24", "17"]

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // xib 설정
        weaklyWeatherTableView.register(UINib(nibName: "WeaklyWeatherTableViewCell", bundle: nil), forCellReuseIdentifier: "weatherTableViewCell")
        
    }
}


extension ViewController: UITableViewDelegate, UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        weatherData.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = weaklyWeatherTableView.dequeueReusableCell(withIdentifier: "weatherTableViewCell", for: indexPath) as! WeaklyWeatherTableViewCell
        
        cell.maximumTeperatureLabel.text = weatherData[indexPath.row]
        
        return cell
    }
}

애플 공식 문서