gpt4 book ai didi

ios - 如何使TableView单元格水平和垂直大小不同?

转载 作者:行者123 更新时间:2023-11-30 12:21:27 25 4
gpt4 key购买 nike

如何使我的表格 View 看起来更像这样,而不仅仅是标准水平单元格。我希望它看起来像下面的示例图片,我需要做什么?我的 tableView 代码也在下面。

enter image description here enter image description here

import UIKit
import Firebase
import FirebaseDatabase
import SDWebImage

struct postStruct {
let title : String!
let author : String!
let date : String!
let article : String!
let downloadURL : String!

}

class NewsViewController: UITableViewController {
var posts = [postStruct]()
override func viewDidLoad() {
super.viewDidLoad()


let ref = Database.database().reference().child("Posts")

ref.observeSingleEvent(of: .value, with: { snapshot in
print(snapshot.childrenCount)
for rest in snapshot.children.allObjects as! [DataSnapshot] {
guard let value = rest.value as? Dictionary<String,Any> else { continue }
guard let title = value["Title"] as? String else { continue }
guard let downloadURL = value["Download URL"] as? String else { continue }
guard let author = value["Author"] as? String else { continue }
guard let date = value["Date"] as? String else { continue }
guard let article = value["Article"] as? String else { continue }

let post = postStruct(title: title, author: author, date: date, article: article, downloadURL: downloadURL)
self.posts.append(post)
}
self.posts = self.posts.reversed(); self.tableView.reloadData()
})
}

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!
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "detail" {
if let indexPath = tableView.indexPathForSelectedRow {
let destVC = segue.destination as! DetailNewsViewController
destVC.titleText = posts[indexPath.row].title
destVC.dateText = posts[indexPath.row].date
destVC.authorText = posts[indexPath.row].author
destVC.bodyText = posts[indexPath.row].article
destVC.headerPhoto = posts[indexPath.row].downloadURL
}
}
}
}

最佳答案

也许您可以在 Storyboard中使用具有不同标识符的不同单元格。根据需要设计每个单元格,并在使用单元格 rowAtIndexPath 时返回您想要的单元格。

关于ios - 如何使TableView单元格水平和垂直大小不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44743178/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com