반응형

 

table cell에 identifier을 type1으로 넣어주었고, content을 dynamic으로 정해주었다.

 

type1.swift  클래스를 만들어준다

 

type1클래스를 만들어준다. type1에 class내용에 type1을 넣어준다.

//
//  type1.swift
//  newsApp
//

import UIKit

class type1 : UITableViewCell {
    
    //label
    @IBOutlet weak var typelabel: UILabel!
    
    
}

 

//
//  ViewController.swift
//  newsApp

import UIKit

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    
    @IBOutlet weak var tableViewMain: UITableView!
    
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        //몇개? 숫자
        return 10
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        //무엇? 반복 10번?
        //2번째 방법 재사용 셀, 친자확인 후 자식 데려오기
        let cell = tableViewMain.dequeueReusableCell(withIdentifier: "type1", for: indexPath) as! type1
        
        //as : as? as! = 친자확인
        
        cell.typelabel.text = "\(indexPath.row)"
        
        return cell
        
    }
    
    //클릭시 - 이벤트
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print("\(indexPath.row)")
    }
    

    override func viewDidLoad() {
        super.viewDidLoad()
       
        
        //self : class viewcontroller 안의 func들을 의미함.
        tableViewMain.delegate = self
        tableViewMain.dataSource = self
    }

    //tableview : 테이블로 된 뷰 - 여러개의 행이 모여있는 화면 목록
    //1. 데이터 무엇?
    //2. 데이터 몇개?

}

by 유투버 센치한개발자

반응형

+ Recent posts