gpt4 book ai didi

ios - 随着内容的增加,努力调整单元格高度

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

我几乎经常努力创建一个高度随内容调整的单元格,同时尝试以编程方式进行,我正在尝试的一些事情是,图像显示了问题
enter image description here

  • 使用以下功能
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {      
    return UITableView.automaticDimension
    }

  • 2)在 viewDidLoad 中使用它
    tableView.rowHeight = UITableView.automaticDimension
    tableView.estimatedRowHeight = 100
  • 设置bottom and top constraints to equal rather then not equal

  • 下面我粘贴了一些代码来展示我的挣扎或尝试一切以使单元格随内容扩展,它确实如此。不,任何人都可以建议一些方法来实现它
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {


    switch indexPath.row {
    case 0:
    let cell = restaurantMainTable.dequeueReusableCell(withIdentifier: String(describing: RestaurantMainViewCells.self), for: indexPath) as! RestaurantMainViewCells

    cell.heightAnchor.constraint(greaterThanOrEqualToConstant: 60).isActive = true
    view.addSubview(cell)
    view.addSubview(cell.contentView)
    view.addSubview(cell.restaurantName)
    view.addSubview(cell.restaurantType)
    view.addSubview(cell.restaurantLocation)
    view.addSubview(cell.restaurantMiniImage)
    view.addSubview(cell.restaurantHeartImage)

    cell.restaurantHeartImage.translatesAutoresizingMaskIntoConstraints = false
    cell.restaurantMiniImage.translatesAutoresizingMaskIntoConstraints = false
    cell.restaurantName.translatesAutoresizingMaskIntoConstraints = false
    cell.restaurantLocation.translatesAutoresizingMaskIntoConstraints = false
    cell.restaurantType.translatesAutoresizingMaskIntoConstraints = false


    //Fonts
    let font = UIFont(name: "Rubik-Medium", size: 18)
    let fontMetrics = UIFontMetrics(forTextStyle: .body)

    let labels = [cell.restaurantName, cell.restaurantLocation, cell.restaurantType]
    labels.forEach { label in
    label.font = fontMetrics.scaledFont(for: font!)
    }

    let stackLabels = UIStackView()
    view.addSubview(stackLabels)

    stackLabels.alignment = .top
    stackLabels.distribution = .fill
    stackLabels.spacing = 5
    stackLabels.axis = .vertical

    stackLabels.addArrangedSubview(cell.restaurantName)
    stackLabels.addArrangedSubview(cell.restaurantType)
    stackLabels.addArrangedSubview(cell.restaurantLocation)

    let stackImage = UIStackView()
    view.addSubview(stackImage)
    stackLabels.translatesAutoresizingMaskIntoConstraints = false
    stackImage.alignment = .top
    stackImage.distribution = .fill
    stackImage.axis = .horizontal
    stackImage.spacing = 5


    cell.restaurantMiniImage.heightAnchor.constraint(equalToConstant: 60).isActive = true
    cell.restaurantMiniImage.widthAnchor.constraint(equalToConstant: 60).isActive = true
    cell.restaurantMiniImage.layer.cornerRadius = 30
    cell.restaurantMiniImage.clipsToBounds = true

    cell.restaurantHeartImage.heightAnchor.constraint(equalToConstant: 20).isActive = true
    cell.restaurantHeartImage.widthAnchor.constraint(equalToConstant: 20).isActive = true
    cell.restaurantHeartImage.trailingAnchor.constraint(equalTo: cell.trailingAnchor, constant: -10).isActive = true
    cell.restaurantHeartImage.topAnchor.constraint(equalTo: cell.topAnchor, constant: 20).isActive = true



    stackImage.addArrangedSubview(cell.restaurantMiniImage)
    stackImage.addArrangedSubview(stackLabels)

    view.addSubview(stackImage)
    stackImage.translatesAutoresizingMaskIntoConstraints = false
    stackImage.leadingAnchor.constraint(equalTo: cell.leadingAnchor, constant: 10).isActive = true
    stackImage.topAnchor.constraint(greaterThanOrEqualTo: cell.topAnchor, constant: 10).isActive = true
    // stackImage.topAnchor.constraint(equalTo: cell.topAnchor, constant: 10).isActive = true

    stackImage.trailingAnchor.constraint(equalTo: cell.restaurantHeartImage.leadingAnchor, constant: -10).isActive = true
    // stackImage.bottomAnchor.constraint(equalTo: cell.bottomAnchor, constant: -10).isActive = true
    stackImage.bottomAnchor.constraint(greaterThanOrEqualTo: cell.bottomAnchor, constant: -10).isActive = true

    cell.restaurantName.text = restaurants[indexPath.row].name
    cell.restaurantType.text = restaurants[indexPath.row].type
    cell.restaurantLocation.text = restaurants[indexPath.row].location
    cell.restaurantHeartImage.image = UIImage(named: "heart-tick")
    if let restaurantImage = restaurants[indexPath.row].image {
    cell.restaurantMiniImage.image = UIImage(data: restaurantImage as Data)
    }




    return cell

    default:
    fatalError("no data found")


    }
    }
    更新——全类
    //
    // RestaurantMainController.swift
    // LaVivaRepeat
    //

    //

    import UIKit
    import CoreData

    class RestaurantMainController: UIViewController, UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate {

    var restaurants: [Restaurant] = []
    var fetchResultController: NSFetchedResultsController<Restaurant>!



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

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

    return 1
    }




    let restaurantMainTable = UITableView()

    override func viewDidLoad() {
    super.viewDidLoad()
    view.addSubview(restaurantMainTable)
    //MARK:- add delegates as self, always, else no contact with model will take place
    restaurantMainTable.rowHeight = UITableView.automaticDimension
    restaurantMainTable.estimatedRowHeight = 60

    self.restaurantMainTable.delegate = self
    self.restaurantMainTable.dataSource = self
    self.restaurantMainTable.separatorStyle = .singleLine
    //MARK:- create a view to show when no records are there
    let backGroundView = UIView()
    view.addSubview(backGroundView)

    backGroundView.heightAnchor.constraint(equalToConstant: 500).isActive = true


    let backGroundImage = UIImageView()
    backGroundImage.translatesAutoresizingMaskIntoConstraints = false
    backGroundView.translatesAutoresizingMaskIntoConstraints = false
    backGroundImage.heightAnchor.constraint(equalToConstant: 300).isActive = true
    backGroundImage.widthAnchor.constraint(equalToConstant: 320).isActive = true
    backGroundImage.image = UIImage(named: "empty")
    backGroundView.addSubview(backGroundImage)

    backGroundView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 30).isActive = true
    backGroundView.topAnchor.constraint(equalTo: view.topAnchor, constant: 90).isActive = true
    backGroundView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 20).isActive = true
    restaurantMainTable.backgroundView = backGroundView
    restaurantMainTable.backgroundView?.isHidden = true



    //MARK:- Add constraints to table

    self.restaurantMainTable.translatesAutoresizingMaskIntoConstraints = false
    self.restaurantMainTable.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
    self.restaurantMainTable.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
    self.restaurantMainTable.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
    self.restaurantMainTable.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true

    //MARK:- register RestaurantMainViewCells
    self.restaurantMainTable.register(RestaurantMainViewCells.self, forCellReuseIdentifier: String(describing: RestaurantMainViewCells.self))

    //MARK:- Get fetch request

    let fetchRequest: NSFetchRequest<Restaurant> = Restaurant.fetchRequest()
    let sortDescriptor = NSSortDescriptor(key: "name", ascending: true)
    fetchRequest.sortDescriptors = [sortDescriptor]

    if let appDelegate = (UIApplication.shared.delegate as? AppDelegate) {
    let context = appDelegate.persistentContainer.viewContext
    fetchResultController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: context, sectionNameKeyPath: nil, cacheName: nil)
    fetchResultController.delegate = self

    do {
    try fetchResultController.performFetch()
    if let fetchObject = fetchResultController.fetchedObjects {
    restaurants = fetchObject
    }
    }

    catch {
    print(error)
    }
    }

    }


    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    restaurantMainTable.rowHeight = UITableView.automaticDimension
    switch indexPath.row {
    case 0:
    let cell = restaurantMainTable.dequeueReusableCell(withIdentifier: String(describing: RestaurantMainViewCells.self), for: indexPath) as! RestaurantMainViewCells

    // cell.heightAnchor.constraint(greaterThanOrEqualToConstant: 60).isActive = true
    view.addSubview(cell)
    view.addSubview(cell.contentView)
    view.addSubview(cell.restaurantName)
    view.addSubview(cell.restaurantType)
    view.addSubview(cell.restaurantLocation)
    view.addSubview(cell.restaurantMiniImage)
    view.addSubview(cell.restaurantHeartImage)

    cell.restaurantHeartImage.translatesAutoresizingMaskIntoConstraints = false
    cell.restaurantMiniImage.translatesAutoresizingMaskIntoConstraints = false
    cell.restaurantName.translatesAutoresizingMaskIntoConstraints = false
    cell.restaurantLocation.translatesAutoresizingMaskIntoConstraints = false
    cell.restaurantType.translatesAutoresizingMaskIntoConstraints = false


    //Fonts
    let font = UIFont(name: "Rubik-Medium", size: 18)
    let fontMetrics = UIFontMetrics(forTextStyle: .body)

    let labels = [cell.restaurantName, cell.restaurantLocation, cell.restaurantType]
    labels.forEach { label in
    label.font = fontMetrics.scaledFont(for: font!)
    }

    let stackLabels = UIStackView()
    view.addSubview(stackLabels)

    stackLabels.alignment = .top
    stackLabels.distribution = .fill
    stackLabels.spacing = 5
    stackLabels.axis = .vertical

    stackLabels.addArrangedSubview(cell.restaurantName)
    stackLabels.addArrangedSubview(cell.restaurantType)
    stackLabels.addArrangedSubview(cell.restaurantLocation)

    let stackImage = UIStackView()
    view.addSubview(stackImage)
    stackLabels.translatesAutoresizingMaskIntoConstraints = false
    stackImage.alignment = .top
    stackImage.distribution = .fill
    stackImage.axis = .horizontal
    stackImage.spacing = 5


    cell.restaurantMiniImage.heightAnchor.constraint(equalToConstant: 60).isActive = true
    cell.restaurantMiniImage.widthAnchor.constraint(equalToConstant: 60).isActive = true
    cell.restaurantMiniImage.layer.cornerRadius = 30
    cell.restaurantMiniImage.clipsToBounds = true

    cell.restaurantHeartImage.heightAnchor.constraint(equalToConstant: 20).isActive = true
    cell.restaurantHeartImage.widthAnchor.constraint(equalToConstant: 20).isActive = true
    cell.restaurantHeartImage.trailingAnchor.constraint(equalTo: cell.trailingAnchor, constant: -10).isActive = true
    cell.restaurantHeartImage.topAnchor.constraint(equalTo: cell.topAnchor, constant: 20).isActive = true



    stackImage.addArrangedSubview(cell.restaurantMiniImage)
    stackImage.addArrangedSubview(stackLabels)

    view.addSubview(stackImage)
    stackImage.translatesAutoresizingMaskIntoConstraints = false
    stackImage.leadingAnchor.constraint(equalTo: cell.leadingAnchor, constant: 10).isActive = true
    stackImage.topAnchor.constraint(greaterThanOrEqualTo: cell.topAnchor, constant: 10).isActive = true
    // stackImage.topAnchor.constraint(equalTo: cell.topAnchor, constant: 10).isActive = true

    stackImage.trailingAnchor.constraint(equalTo: cell.restaurantHeartImage.leadingAnchor, constant: -10).isActive = true
    // stackImage.bottomAnchor.constraint(equalTo: cell.bottomAnchor, constant: -10).isActive = true
    stackImage.bottomAnchor.constraint(greaterThanOrEqualTo: cell.bottomAnchor, constant: -10).isActive = true

    cell.restaurantName.text = restaurants[indexPath.row].name
    cell.restaurantType.text = restaurants[indexPath.row].type
    cell.restaurantLocation.text = restaurants[indexPath.row].location
    cell.restaurantHeartImage.image = UIImage(named: "heart-tick")
    if let restaurantImage = restaurants[indexPath.row].image {
    cell.restaurantMiniImage.image = UIImage(data: restaurantImage as Data)
    }




    return cell

    default:
    fatalError("no data found")


    }
    }
    //MARK:- Make custom navigation bar large font size and use rubik fonts


    override func viewWillAppear(_ animated: Bool) {



    navigationController?.navigationBar.prefersLargeTitles = true
    self.navigationController?.navigationBar.topItem?.title = "LaViva Hotel"
    navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
    navigationController?.navigationBar.shadowImage = UIImage()
    navigationController?.hidesBarsOnSwipe = true

    if let customFont = UIFont(name: "Rubik-Medium", size: 40) {
    navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor(red: 200/255, green: 70/255, blue: 70/255, alpha: 1), NSAttributedString.Key.font: customFont]
    }

    //MARK:- for empty table
    if restaurants.count > 0 {
    self.restaurantMainTable.backgroundView?.isHidden = true
    self.restaurantMainTable.separatorStyle = .singleLine

    }
    else {
    self.restaurantMainTable.backgroundView?.isHidden = false
    self.restaurantMainTable.separatorStyle = .none

    }

    //MARK:- make an + button appear on top left
    let addButton = UIBarButtonItem(image: UIImage(named: "plus"), style: .plain, target: self, action: #selector(addNewRestaurant))

    //navigationController?.navigationItem.rightBarButtonItem = addButton
    self.navigationItem.rightBarButtonItem = addButton

    }

    //MARK:- addNewRestaurant function
    @objc func addNewRestaurant() {
    let pushController = RestaurantAddController()
    navigationController?.pushViewController(pushController, animated: true)
    }

    //MARK:- try and show cell and tower as default or dark done here


    override var preferredStatusBarStyle: UIStatusBarStyle {
    return .default
    }


    //add update delete

    func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
    restaurantMainTable.beginUpdates()
    }

    func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
    switch type {
    case .insert:
    if let newIndexPath = newIndexPath {
    restaurantMainTable.insertRows(at: [newIndexPath], with: .fade)
    }

    case .delete:
    if let indexPath = indexPath {
    restaurantMainTable.deleteRows(at: [indexPath], with: .fade)
    }

    case .update:
    if let indexPath = indexPath {
    restaurantMainTable.reloadRows(at: [indexPath], with: .fade)
    }
    default:
    restaurantMainTable.reloadData()

    }

    if let fetchedObjects = controller.fetchedObjects {
    restaurants = fetchedObjects as! [Restaurant]
    }
    }


    func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
    restaurantMainTable.endUpdates()



    }

    //MARK:- left swipr delete

    func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    let deleteAction = UIContextualAction(style: .destructive, title: "Delete") { (action, view, completionHandler) in

    if let appDelegate = (UIApplication.shared.delegate as? AppDelegate) {
    let context = appDelegate.persistentContainer.viewContext
    let restaurantsToDelete = self.fetchResultController.object(at: indexPath)
    context.delete(restaurantsToDelete)
    appDelegate.saveContext()
    }

    completionHandler(true)

    }

    let swipeConfiguration: UISwipeActionsConfiguration
    swipeConfiguration = UISwipeActionsConfiguration(actions: [deleteAction])
    return swipeConfiguration
    }

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return UITableView.automaticDimension
    }

    func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
    return UITableView.automaticDimension
    }





    }
    更新
    import UIKit

    class RestaurantMainViewCells: UITableViewCell {

    var restaurantMiniImage = UIImageView()

    var restaurantHeartImage = UIImageView()
    var restaurantName = UILabel()
    var restaurantType = UILabel()
    var restaurantLocation = UILabel()

    override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    // Configure the view for the selected state
    }

    }

    最佳答案

    您的所有单元格设置 - 添加和约束 UI 元素 - 都应该在您的单元格类中完成。 绝对不是 cellForRowAt .
    您最好阅读一些有关创建动态单元格的教程。
    但是,为了给你一个想法,这里是你的代码修改,所以你可以看到发生了什么:

    struct Restaurant {
    var name: String = ""
    var type: String = ""
    var location: String = ""

    // however you have your image information stored
    //var image
    }

    class RestaurantMainViewCells: UITableViewCell {

    var restaurantMiniImage = UIImageView()
    var restaurantHeartImage = UIImageView()
    var restaurantName = UILabel()
    var restaurantType = UILabel()
    var restaurantLocation = UILabel()

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)
    commonInit()
    }

    required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
    }

    func commonInit() -> Void {

    // so we can see the image view frames without actual images...
    restaurantMiniImage.backgroundColor = .green
    restaurantHeartImage.backgroundColor = .red

    var font: UIFont = UIFont.systemFont(ofSize: 18)

    if let f = UIFont(name: "Rubik-Medium", size: 18) {
    font = f
    }
    let fontMetrics = UIFontMetrics(forTextStyle: .body)

    let labels = [restaurantName, restaurantLocation, restaurantType]
    labels.forEach { label in
    label.font = fontMetrics.scaledFont(for: font)
    // so we can see label frames...
    label.backgroundColor = .yellow
    }

    let stackLabels = UIStackView()
    stackLabels.alignment = .fill
    stackLabels.distribution = .fill
    stackLabels.spacing = 5
    stackLabels.axis = .vertical

    stackLabels.addArrangedSubview(restaurantName)
    stackLabels.addArrangedSubview(restaurantType)
    stackLabels.addArrangedSubview(restaurantLocation)

    let stackImage = UIStackView()
    stackImage.alignment = .top
    stackImage.distribution = .fill
    stackImage.axis = .horizontal
    stackImage.spacing = 5

    restaurantMiniImage.layer.cornerRadius = 30
    restaurantMiniImage.clipsToBounds = true

    stackImage.addArrangedSubview(restaurantMiniImage)
    stackImage.addArrangedSubview(stackLabels)
    contentView.addSubview(stackImage)
    contentView.addSubview(restaurantHeartImage)

    restaurantHeartImage.translatesAutoresizingMaskIntoConstraints = false
    stackImage.translatesAutoresizingMaskIntoConstraints = false

    NSLayoutConstraint.activate([

    // mini image 60x60
    restaurantMiniImage.heightAnchor.constraint(equalToConstant: 60),
    restaurantMiniImage.widthAnchor.constraint(equalToConstant: 60),

    // heart image 20 x 20
    restaurantHeartImage.heightAnchor.constraint(equalToConstant: 20),
    restaurantHeartImage.widthAnchor.constraint(equalToConstant: 20),

    // heart image top+20 trailing-10
    restaurantHeartImage.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 20),
    restaurantHeartImage.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -10),

    // horizontal stack top / leading / bottom and trailinh to heart image
    // all with 10-pts "padding"
    stackImage.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 10),
    stackImage.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 10),

    stackImage.trailingAnchor.constraint(equalTo: restaurantHeartImage.leadingAnchor, constant: -10),
    stackImage.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -10),

    ])

    }
    }

    class RestaurantMainController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    var restaurants: [Restaurant] = []


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

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

    let restaurantMainTable = UITableView()

    override func viewDidLoad() {
    super.viewDidLoad()

    view.addSubview(restaurantMainTable)

    //MARK:- add delegates as self, always, else no contact with model will take place
    restaurantMainTable.estimatedRowHeight = 60

    self.restaurantMainTable.delegate = self
    self.restaurantMainTable.dataSource = self

    self.restaurantMainTable.separatorStyle = .singleLine

    //MARK:- Add constraints to table
    self.restaurantMainTable.translatesAutoresizingMaskIntoConstraints = false

    NSLayoutConstraint.activate([
    restaurantMainTable.topAnchor.constraint(equalTo: view.topAnchor),
    restaurantMainTable.bottomAnchor.constraint(equalTo: view.bottomAnchor),
    restaurantMainTable.leadingAnchor.constraint(equalTo: view.leadingAnchor),
    restaurantMainTable.trailingAnchor.constraint(equalTo: view.trailingAnchor),
    ])

    //MARK:- register RestaurantMainViewCells
    self.restaurantMainTable.register(RestaurantMainViewCells.self, forCellReuseIdentifier: String(describing: RestaurantMainViewCells.self))

    //MARK:- Get fetch request

    // I don't have your "fetch" data, so I'm just adding a couple restaurants here
    restaurants.append(Restaurant(name: "Cafe De Loir", type: "Chinese Cousine", location: "Hong Kong"))
    restaurants.append(Restaurant(name: "Bob's Cafe", type: "Japanese Cousine", location: "Tokyo"))
    restaurants.append(Restaurant(name: "Mary's Restaurant", type: "Home Cooking", location: "Dallas, Texas"))

    // let fetchRequest: NSFetchRequest<Restaurant> = Restaurant.fetchRequest()
    // let sortDescriptor = NSSortDescriptor(key: "name", ascending: true)
    // fetchRequest.sortDescriptors = [sortDescriptor]
    //
    // if let appDelegate = (UIApplication.shared.delegate as? AppDelegate) {
    // let context = appDelegate.persistentContainer.viewContext
    // fetchResultController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: context, sectionNameKeyPath: nil, cacheName: nil)
    // fetchResultController.delegate = self
    //
    // do {
    // try fetchResultController.performFetch()
    // if let fetchObject = fetchResultController.fetchedObjects {
    // restaurants = fetchObject
    // }
    // }
    //
    // catch {
    // print(error)
    // }
    // }

    }


    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: RestaurantMainViewCells.self), for: indexPath) as! RestaurantMainViewCells

    let r = restaurants[indexPath.row]

    cell.restaurantName.text = r.name
    cell.restaurantType.text = r.type
    cell.restaurantLocation.text = r.location

    //if let restaurantImage = restaurants[indexPath.row].image {
    // cell.restaurantMiniImage.image = UIImage(data: restaurantImage as Data)
    //}

    cell.restaurantHeartImage.image = UIImage(named: "heart-tick")

    return cell

    }

    }
    结果(我没有您的图像,因此 ImageView 具有绿色或红色背景色):
    enter image description here

    关于ios - 随着内容的增加,努力调整单元格高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63078055/

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