我有UIView
的自定义视图,在init
方法中,如下所示:
-(instancetype)init
{
if ([super init])
{
self.frame = [UIScreen mainScreen].bounds;
or self = [[UIView alloc]init];
}
return self;
}
它从不显示错误,但是当我使用swift时
init() {
self.frame = UIScreen.mainScreen().bounds
}
编译告诉我:
在从初始化返回之前,不会在所有路径上调用
Super.init
然后我添加super.init()
,编译器告诉我:
此处声明便利初始值设定项(
UIKit.UIView
)
如何在Swift self = [[UIView alloc]init];
方法中使用init
之类的初始方法?
答案 0 :(得分:0)
试试这个...
init()
{
super.init(frame: UIScreen.mainScreen().bounds)
// Other initialization operations...
}