如何使每个tableview单元格的大小不同?
问题描述:
如何将我的第一个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!
}
答
你应该使用这个功能
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == 0{
return 70.0
}
return 35.0
}
感谢它的作品!你是否也知道如何让每个细胞再次成为两倍的细胞? – Riccardo
是的,你可以改变你的逻辑。如果indexPath.row%5 == 0 –
谢谢!我怎样才能让标题移动,所以它不会被切断? – Riccardo