2017-06-23 6 views
2

最初のテーブルビューセルを次のセルの残りの部分の高さの2倍にするにはどうすればよいですか?どのように各テーブルビューのセルを異なるサイズにするか?

これは私のテーブルビューのコードです:

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return posts.count 
} 

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell") 

    let label1 = cell?.viewWithTag(1) as! UILabel 
    label1.text = posts[indexPath.row].title 

    let imageView = cell?.viewWithTag(2) as! UIImageView 
    let post = self.posts[indexPath.row]; 
    imageView.sd_setImage(with: URL(string: post.downloadURL), placeholderImage: UIImage(named: "placeholder")) 

    return cell! 
} 

This is my storyboard for the tableview and its cell

答えて

3

あなたがこの機能にそれが動作

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 

     if indexPath.row == 0{ 
      return 70.0 

     } 
     return 35.0 
    } 
+0

感謝を使用する必要があります!また、5回ごとに5倍のセルを2倍にする方法も分かっていますか? – Riccardo

+1

はい、このようなロジックを変更することができます。 if indexPath.row%5 == 0 –

+0

ありがとう!どのようにタイトルを手に入れてもらうと、それは途切れることはありませんか? – Riccardo

関連する問題