UICollectionView F#在init中调用方法 [] 键入ChatViewCell(句柄:IntPtr),如下所示: 继承UICollectionViewCell(句柄) []静态val可变私有id:NSString 静态成员初始化= printfn“初始化ChatViewCell” ChatViewCell.id

UICollectionView F#在init中调用方法 [] 键入ChatViewCell(句柄:IntPtr),如下所示: 继承UICollectionViewCell(句柄) []静态val可变私有id:NSString 静态成员初始化= printfn“初始化ChatViewCell” ChatViewCell.id,f#,xamarin.ios,uicollectionview,initialization,uicollectionviewcell,F#,Xamarin.ios,Uicollectionview,Initialization,Uicollectionviewcell,setupView被定义为实例函数,因为它没有静态修饰符。它必须是实例函数(或实例方法),因为它访问作为实例字段的profileImageView 静态成员init无法调用实例函数,因为无法将实例显式传递给实例函数(只能将实例显式传递给方法) 如果您想在构建ChatViewCell时进行初始化,只需将初始化语句放在类的主体中即可。执行此操作时,需要使用通常隐式的do关键字 e、 g 键入ChatViewCell(句柄:IntPtr),如下所示= 继承UICollectionViewCell(句柄

setupView
被定义为实例函数,因为它没有
静态
修饰符。它必须是实例函数(或实例方法),因为它访问作为实例字段的
profileImageView

静态成员
init
无法调用实例函数,因为无法将实例显式传递给实例函数(只能将实例显式传递给方法)

如果您想在构建
ChatViewCell
时进行初始化,只需将初始化语句放在类的主体中即可。执行此操作时,需要使用通常隐式的
do
关键字

e、 g

键入ChatViewCell(句柄:IntPtr),如下所示=
继承UICollectionViewCell(句柄)
让可变profileImageView=new UIImageView()
执行profileImageView.Frame
 [<Register ("ChatViewCell")>]
type ChatViewCell (handle: IntPtr) as this = 
    inherit UICollectionViewCell (handle)


    [<DefaultValue>] static val mutable private id : NSString

    static member init = 
        printfn "Initializing ChatViewCell."
        ChatViewCell.id <- new NSString("ChatCell")


    override this.ReuseIdentifier = ChatViewCell.id

    let mutable profileImageView = new UIImageView()
    let mutable nameLabel = new UILabel()
    let mutable messageLabel = new UILabel()
    let mutable timeofMessageLabel = new UILabel()
    let mutable dividerLineView = new UIView()
    let mutable countLabel = new UILabel()

    let setupView() = 
        profileImageView.Frame <- CGRect(50.0, 0.0, 200.0, 100.0)
        profileImageView.ContentMode <- UIViewContentMode.ScaleAspectFill
        profileImageView.Layer.CornerRadius <- Conversions.nfloat(30)
type ChatViewCell (handle: IntPtr) as this = 
    inherit UICollectionViewCell (handle)

    let mutable profileImageView = new UIImageView()

    do profileImageView.Frame <- CGRect(50.0, 0.0, 200.0, 100.0)
    do profileImageView.ContentMode <- UIViewContentMode.ScaleAspectFill
    do profileImageView.Layer.CornerRadius <- Conversions.nfloat(30)