【发布时间】:2020-02-11 23:06:34
【问题描述】:
我需要添加一个viewcontroller作为mt当前视图的子视图,但是在我不再需要它之后无法deinit
let viewController = CountrySelectViewController()
viewController.view.frame = self.view.bounds
viewController.view.alpha=0
self.view.addSubview(viewController.view)
UIView.animate(withDuration: 0.25, delay: 0.0, options: [], animations: {
viewController.view.alpha=1
}, completion: { (finished: Bool) in
})
viewController.completionHandlerClose = {
UIView.animate(withDuration: 0.25, delay: 0.0, options: [], animations: {
viewController.view.alpha=0
}, completion: { (finished: Bool) in
viewController.view.removeFromSuperview()
viewController.view = nil
})
}
【问题讨论】:
-
使其可以为空,然后如果你想取消初始化,那么将它的值设置为 nil
-
我怎样才能让它为空?
-
yourController = nil
-
'nil' 不能分配给类型 'CountrySelectViewController'
-
这样描述你的控制器 var yourController:CountryController?
标签: ios swift uiviewcontroller deinit