简体   繁体   中英

How to use a UICollectionViewCell in a UITableView?

I have a cell originally created as a UICollectionViewCell but I want to be able to reuse it in a UITableView . Would I simply have to reimplement it in the form of a UITableView or is there any alternative?

The UITableView needs to present the exact same cell as well, but it can't because of the lack of cross-compatibility. My original cell is declared as such and uses a NIB file for the UI layout:

class originalCollectionViewCell: UICollectionViewCell {
    //parent view that nests several other views
    @IBOutlet weak var viewBackground: UIView! 

    override func awakeFromNib() {
        ...
    }
}

If I'm understanding the question correctly, I'd recommend creating a subclass of UIView and move the subviews that are currently in your collection view cell into this subclass. Then use this subview as the contentView of both your collection view cell and table view cell.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM