iOS UITableView


필수 함수 몇 개

func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}
    
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 7
}
    
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    switch indexPath.row {
    let cell = tableView.dequeueReusableCell(withIdentifier: "SWITCH_CELL", for: indexPath) as? SwitchTVCell
    cell!.label?.text = "다크 테마"
    cell!.swOnOff.setOn(true, animated: false)
    /*
    if isLock {
    cell!.swOnOff.setOn(true, animated: false)
    }
    else {
    cell!.swOnOff.setOn(false, animated: false)
    }
    */
    cell!.delegate = self
    cell!.tag = 1005
    cell!.selectionStyle = .none
            
    return cell!
}
    
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    switch indexPath.row {
    case 0:
        print("switchCell tapped.")
    case 1:
        print("switchCell tapped.")
    case 2:
        print("switchCell tapped.")
    case 3:
        print("basicCell tapped.")
    default:
        print("default")
    }
}

custom cell

UIViewController 에 UITableView 를 올리고, 그 위에 UITableViewCell 을 올린다.

Prototype Cells 라고 헤더가 생기고 빈 셀이 하나 추가된다.

Table View 인스펙터에 가서

  • Content : Dynamic Prototypes
  • Prototype Cells 갯수 설정

cell 사이 구분선 감추기

tableView.separatorStyle = .none

hide empty Cells

func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    return UIView()
}
,

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다