我尝试使用NSPageController
创建向导。但我不明白我需要在委托方法中返回什么。我将navigateForward
附加到我的按钮上,当我点击它时,我得到:
[__ NSArrayM objectAtIndex:]:索引1超出界限[0 .. 0]
class BoardAligmentPageController: NSPageController, NSPageControllerDelegate {
var orderedViewControllers: [NSViewController] = {
return [NSStoryboard(name: "Main", bundle:nil).instantiateController(withIdentifier: "BoardAligmentStep1ViewController") as! NSViewController,
NSStoryboard(name: "Main", bundle:nil).instantiateController(withIdentifier: "BoardAligmentStep2ViewController") as! NSViewController,
NSStoryboard(name: "Main", bundle:nil).instantiateController(withIdentifier: "BoardAligmentStep2ViewController") as! NSViewController,
]
}()
override func viewDidLoad() {
super.viewDidLoad()
delegate = self
self.arrangedObjects = orderedViewControllers
}
func pageController(_ pageController: NSPageController, identifierFor object: Any) -> String {
return "\(self.selectedIndex)"
}
func pageController(_ pageController: NSPageController, viewControllerForIdentifier identifier: String) -> NSViewController {
return orderedViewControllers[Int(identifier)!]
}
}
答案 0 :(得分:1)
看起来您的orderedViewControllers
属性实际上并未设置(因为您正在获得"超出界限"错误)。
不要使用该属性,而是尝试按需执行:
func pageController(_ pageController: NSPageController, identifierFor object: Any) -> String {
print("\(self.selectedIndex)")
switch(self.selectedIndex)
{
case 0 :
return "BoardAligmentStep1ViewController"
case 1 :
return "BoardAligmentStep2ViewController"
case 2 :
return "BoardAligmentStep3ViewController"
default :
return "SomeDefaultViewController"
}
}
func pageController(_ pageController: NSPageController, viewControllerForIdentifier identifier: String) -> NSViewController {
return self.storyboard?.instantiateController(withIdentifier: identifier) as! NSViewController
}