Just contact with Swift and iOS, not quite understand the logic that leads to some problems. Share the Swift custom Uicollectionviewcell here
First of all my viewcontroller not directly inherit Uicollectionviewcontroller, but add Uicollectionview to my storyboard,
Then create a swift file and let this swift inherit Uicollectionviewcell
Import Foundationclasssvgcell:uicollectionviewcell{convenience required init (coder:nscoder) {self.init (Frame:cgrect (x: 0Y:0, Width: -, Height: -)) } //required Init (coder:nscoder) {//fatalerror ("Nscoding not supported")// } OverrideInit (frame:cgrect) {super.init (frame:frame)}//About Inheritance//http://stackoverflow.com/questions/25126295/swift-class-does-not-implement-its-superclasss-required-members}
When inheriting Uicollectionviewcell here, a parent class initialization method and a required initialization method are required, and a link above is a description of the required method, which is necessary for the new version, otherwise it will report a syntax error. The error content is probably asking you to implement a required method.
It is not possible to write a custom initialization here because this cell is not created by Init.
And go back to our viewcontroller.
Import UIKit class Viewcontroller:uiviewcontroller, Uicollectionviewdatasource,uicollectionviewdelegate {//inherit the following two protocols, You need to use CollectionView and then you can make a copy of the following three required methods var svgcollection:uicollectionview!
Let reuseidentifier="Svgcell"
func CollectionView (Collectionview:uicollectionview!, Numberofitemsinsection Section:int)Int {return 2 }//These 3 func inherit the DataSource & delegate must be rewritten, if there are multiple TableView or collection view in the inside use judgment, the parameter CollectionView judgefunc CollectionView (Collectionview:uicollectionview!, Cellforitematindexpath indexpath:nsindexpath!) uicollectionviewcell! { varCell:svgcell=svgcollection.dequeuereusablecellwithreuseidentifier (Reuseidentifier, Forindexpath:indexpath) asSvgcell//Reuse//This cell here doesn't need to be initialized .//construct a cell before return if it is initialized again, it will lead to Uncatch's exception, the content is probably not reuseidentifier returncell}//func Numberofsectionsincollectionview (Collectionview:uicollectionview!) -Int {return 1 }//}
On the inside of the uicollectionview that we added to our storyboard.
The cell inside this column sets its properties
Setting the identifier property is basically done, then you can write the code you need in the custom Uiviewcollectioncell class.