2017-04-19 4 views
0

私は2つのカスタムセルを持っていますが、両方のセルに静的な高さを設定するのに問題があります。最初のセルの高さは100、他のセルの高さは40です。以下のコードは、最初のものの代わりに100の高さ。2つの異なる高さの2つの別個のセルを持つにはどうすればよいですか?

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
     if(indexPath.row == 0) { 
      return 100.0 
     } 
      return 40.0 
    } 
+0

その投稿には高さについて何も言及されていません。 – joethemow

+1

Joeは複製された2番目のリンクを表示します:http://stackoverflow.com/questions/39071603/swift-how-to-set-dynamic-cell-height-in-tableviewcontroller-which-contains-more – JAL

答えて

0

最初のセルを別のセクションに配置することができます。

func numberOfSections(in tableView: UITableView) -> Int { 
    return 2 
} 

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    if section == 0 { 
     return 1 
    }else { 
     return yourArray.count 
} 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    if indexPath.section == 1 { 
     let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as! FirstCustomCell 
     return cell 
    }else{ 
     let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as! SecondCustomCell 
     return cell 
} 

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
    if indexPath.section == 1 { 
     return 100 
    } else{ 
     return 40 
} 
関連する問題