在swift中导入DropDown时ImageView如何工作?

问题描述 投票:0回答:1

我希望它能够在单击按钮时在单元格中显示图像和文本,但它不起作用

import UIKit
import DropDown

class MyDropDownCell: DropDownCell {
    
    @IBOutlet weak var logoImage: UIImageView!
    
    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
    }
    
}

@objc func buttonTapped(_ sender: UIButton) {
    let array = ["uploadvalidation","trashAdd"]
    dropDown.dataSource = ["Download report","Delete"]
    
    dropDown.anchorView = sender
    dropDown.cornerRadius = 20.0
    dropDown.bottomOffset = CGPoint(x: -140 , y: 26)
    dropDown.backgroundColor = .orange
    dropDown.show()
    dropDown.cellNib = UINib(nibName: "MyDropDownCell", bundle: Bundle(for: type(of: self)))
    print("Cell created: \(MyDropDownCell.self)")
    dropDown.customCellConfiguration = { (index: Index, item: String, cell: DropDownCell) -> Void in
        guard let cell = cell as? MyDropDownCell else { return }
        print("Index: \(index), Item: \(item), Image Name: \(array[index])")
        // Setup your custom UI components
        
        
        cell.logoImage.image = UIImage(named: array[index])
    }
    
}

enter image description here

我已经尝试了一切,但还是不行

swift uitableview drop-down-menu uikit
1个回答
0
投票

尝试重新加载您正在使用 MyDropDownCell 的 tableView

© www.soinside.com 2019 - 2024. All rights reserved.