我有一个用于 SegmentedPageViewController 的自定义类。该 View Controller 包含一个IBOutlet,它是segmentedControl。我创建了两个方法来配置高度和字体,以便我可以在prepareForSegue() 中的 View Controller 中调用这些属性。
在我的自定义类中:
func setHeightConstraint(height:CGFloat) {
segmentedControl.heightAnchor.constraintEqualToConstant(height).active = true
}
func setTitleTextAttributes(dictionary:[NSObject: AnyObject]) {
segmentedControl.setTitleTextAttributes(dictionary, forState: .Normal)
}
在其他 View Controller 中的prepareForSegue方法中:
segmentedPageViewController.setHeightConstraint(25.0)
segmentedPageViewController.setTitleTextAttributes(NSDictionary(object: UIFont(name: "HelveticaNeue", size: 12.0)!, forKey: NSFontAttributeName) as [NSObject : AnyObject])
我面临的问题是它在上面的“setHeightConstraint”方法上崩溃,因为segmentControl为零。我如何配置它以便引用正确的segmentControl?
最佳答案
在分段 Controller 中创建一个属性,以仅保存您希望其使用的值,而不是 IBOutlet。在准备 segue 时将您的值传递给这个新属性,然后让目标 Controller 使用它在 viewDidload(或更高版本)中的自己的导出上设置约束。
关于ios - 如何在 IBOutlet 上创建可配置属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40371038/