본문 바로가기

iOS/PROJECT

[소리마당 Proj] 메인화면 구성, 테이블뷰 segue 넘기기

혼자하려니 진도가 정말정말 느리다 ㅜ_ㅜ 화이티이이잉

 

알게된 것

  1. xib으로 tableViewCell을 커스텀하였습니다. 세로길이를 고정시키기 위해서 viewDidLoad()에 코드 작성하였습니다.
    heightForRowAt 은 왜 안썻지..
    self.gameTableView.rowHeight = 128​
  2. Cell의 갯수만큼만 line(선)을 표시하였습니다. 
    ➡️  Cell 의 배경색이 지정되어 있어서 충분히 구분감을 주기 때문에 굳이 선을 표시할 필요가 없어  후에 선을 지우게 되었습니다.
    self.gameTableView.tableFooterView = UIView()​
  3. 네비게이션 바를 투명하게 하는 코드
    ➡️ 네비게이션의 타이틀만 표시하기 위해서 작성하였습니다.
    func clearNavigationBarBackgroundColor() {
        self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
        self.navigationController?.navigationBar.shadowImage = UIImage()
        self.navigationController?.navigationBar.isTranslucent = true
        self.navigationController?.view.backgroundColor = .clear
    }​
  4. 특정 Cell 클릭 시 다음 segue로 넘기기 (didSelectRowAt 사용)
    Identifier는 스토리보드의 show로 넘기는 segue 입니다.
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        switch indexPath.row {
        case 1:
            performSegue(withIdentifier: "OXQuiz", sender: nil)
        default:
            return
        }
    }​

 

 

 

 

 

못한 것

  1. 네비게이션 타이틀 폰트 변경
    -> 이걸 변경하니 테이블 뷰의 모든 것이 같이 사라집니다..
    // 실패한 코드
    guard let font: UIFont = UIFont(name: "넥슨Lv1고딕 Low OTF Light", size: 18) else {
        return
    }
    
    self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.font: font]​
  2. 헤드의 배경색, 폰트 변경