PhotoCollectionViewDelegate
有初始化 -
-(instancetype)initWithController:(MyViewController *)controller {
self = [super init];
if(self) {
self.myViewController = controller;
}
return self;
}
从MyViewController.swift
文件中调用
let photoCollectionViewDelegate = PhotoCollectionViewDelegate(controller : self)
gives 'Can not convert value of type MyViewController to expected argument type 'MyViewController!'
即PhotoCollectionViewDelegate(controller : MyViewController!)
,但self
与之呼叫MyViewController
。
答案 0 :(得分:1)
这可能很愚蠢,但你试过了吗?
let photoCollectionViewDelegate = PhotoCollectionViewDelegate(controller : self as MyViewController!)
答案 1 :(得分:1)
试一试:
let optionalSelf = self as MyViewController!
let wrappedSelf = optionalSelf ?? nil
let photoCollectionViewDelegate = PhotoCollectionViewDelegate(controller : wrappedSelf)