【发布时间】:2014-11-05 12:10:28
【问题描述】:
根据View Controller Programming Guide,我们可以通过将nil分配给self.view,从UIViewController显式卸载self.view。
但在 Swift 中,UIViewController 中的 view 属性被声明为
var view: UIView
不是UIView!,因此以下代码无法编译
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
if self.view.window == nil {
self.view = nil
// ^ Type 'UIView' does not conform to protocol 'NilLiteralConvertible'
}
}
在 Swift 中还有其他方法吗?
【问题讨论】:
-
self.view.removeFromSuperview()
-
@ArturKucaj:……完全不同。
标签: ios swift uiviewcontroller