Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios SWIFT中的ChildViewController和IBUIView_Ios_Swift_Uiview_Uiviewcontroller_Iboutlet - Fatal编程技术网

Ios SWIFT中的ChildViewController和IBUIView

Ios SWIFT中的ChildViewController和IBUIView,ios,swift,uiview,uiviewcontroller,iboutlet,Ios,Swift,Uiview,Uiviewcontroller,Iboutlet,我花了几天时间试图解决这个问题,但找不到任何解决方案(除了programmaticaly): 我有2个UIViewController,其中第2个是UIChildViewController。 在ChildViewController中,我有一个IBUIView类的属性链接到情节提要中的CustomClassUIview。 此CustomClassUIview具有更新此类内定义的形状层的方法和属性 问题是,当我尝试访问这个自定义uiview的一个属性时,它返回nil。 我知道IBOutlet在v

我花了几天时间试图解决这个问题,但找不到任何解决方案(除了programmaticaly):

我有2个UIViewController,其中第2个是UIChildViewController。 在ChildViewController中,我有一个IBUIView类的属性链接到情节提要中的CustomClassUIview。 此CustomClassUIview具有更新此类内定义的形状层的方法和属性

问题是,当我尝试访问这个自定义uiview的一个属性时,它返回nil。 我知道IBOutlet在viewDidLoad外启动,ViewWillExample,。。。但我不知道如何保持平衡

我使用故事板是为了更容易设计,但如果我只使用编程,它就可以工作了

请帮忙

class ChildViewController: UIViewController {

@IBOutlet weak var customUIView: CustomClassUIView!

var upperValueProgress:CGFloat = 0 {
    didSet {
        self.customUIView.progress = upperValueProgress
        updateLayerFrames()
    }
} 

override func viewDidLoad() {
    super.viewDidLoad()

    self.view.backgroundColor = UIColor.greenColor()  
}

override func viewWillAppear(animated: Bool) {
    customUIView.progress = 0
}

func updateLayerFrames() {
    customUIView.reveal()
}
}

}

class FirstViewController: UIViewController {

var customUIViewController:ChildViewController!

override func viewDidLoad() {
    super.viewDidLoad()

    self.customUIViewController = ChildViewController()
}
...

func update(){
    self.customUIViewController.upperValueProgress = 56 // Example
}
@IBDesignable class CustomClassUIview: UIView {

let pathLayer = CAShapeLayer()
var circleRadius: CGFloat {
    get {
        return self.frame.width / 2
    }
    set {

    }
}

@IBInspectable var progress: CGFloat = 0 {
    didSet {
        reveal()
    }
}

override init(frame: CGRect) {
    super.init(frame: frame)
    configure()

}

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    configure()
    reveal()

}



func configure() {
    pathLayer.frame = self.bounds
    pathLayer.lineWidth = 2
    pathLayer.backgroundColor = UIColor.clearColor().CGColor
    pathLayer.fillColor = UIColor.clearColor().CGColor
    pathLayer.strokeColor = UIColor.redColor().CGColor
    layer.addSublayer(segmentTimerPathLayer)
    backgroundColor = UIColor.whiteColor()
    progress = 0
}


func circleFrame() -> CGRect {
    var circleFrame = CGRect(x: self.bounds.minX, y: self.bounds.minY, width: 2*circleRadius, height: 2*circleRadius)

    circleFrame.origin.x = 0  
    circleFrame.origin.y = 0 
    return circleFrame
}

func circlePath() -> UIBezierPath {        
    return UIBezierPath(ovalInRect: circleFrame())
}

override func layoutSubviews() {
    super.layoutSubviews()
    pathLayer.frame = bounds
    pathLayer.path = circlePath().CGPath
}

func reveal() {
    println(progress)    
}