这是对此的后续问题:Assign ViewController to Class or vice versa
所以我有一个名为 SwipeStepViewController 的 ViewController,它是 ORKActiveStepViewController 的子类。在 SwipeStep 类中,我尝试用我的自定义 SwipeStepViewController
覆盖默认的 ViewController。
我试图覆盖 +stepViewControllerClass
方法并在 SwipeStep 类中返回我的自定义 View Controller :
导入 ResearchKit
class SwipeStep:ORKActiveStep{
override func stepViewControllerClass(){
return SwipeStepViewController.self
}
}
但这根本行不通。 我使用 researchkit,但我想这是一个普遍的快速问题。
最佳答案
我对 ResearchKit 没有任何经验,但在查看了 Objective-C code 之后我相信你的方法应该是:
override class func stepViewControllerClass() -> AnyClass {
return SwipeStepViewController.self
}
解释为什么会出现错误:
Method does not override any method from its superclass.
and
'SwipeStepViewController.Type' is not convertible to '()'
看看您应该覆盖的类方法(由+
表示):
+ (Class)stepViewControllerClass {
return [ORKFormStepViewController class];
}
将此与您的方法进行比较:
override func stepViewControllerClass(){
return SwipeStepViewController.self
}
这既不是类方法,也不是返回类,而且很清楚错误的来源。
关于swift - 在 Swift 中返回新的 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31119521/