2017-06-23 108 views
2

如何將我的第一個tableview單元格放置到其餘單元格高度的兩倍?如何使每個tableview單元格的大小不同?

這是我的tableview代碼:

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

感謝它的作品!你是否也知道如何讓每個細胞再次成爲兩倍的細胞? – Riccardo

+1

是的,你可以改變你的邏輯。如果indexPath.row%5 == 0 –

+0

謝謝!我怎樣才能讓標題移動,所以它不會被切斷? – Riccardo

相關問題