简体   繁体   中英

Rendering UIView in Swift with @IBDesignable, crash

I have a graph built in Paintcode that I am showing in a UIView. It works fine in the App but will not render in storyboard. I have read a host of different posts about overriding init frame, and init coder. However, I can't find a specific example that helps me with my problem, by showing the practical use of these overrides.

The graph takes 14 variables to produce a bar chart. Here is the class code

import UIKit

@IBDesignable

 class graphRisk: UIView {

 override func drawRect(rect: CGRect) {

    StyleKitGraph.drawRiskGraph(ehsScale: ehsScale, ciScale: ciScale, stratScale: stratScale, qaScale: qaScale, delScale: delScale, leadScale: leadScale, peopScale: peopScale, hrmScale: hrmScale, pmScale: pmScale, costScale: costScale, finScale: finScale, assScale: assScale, itsScale: itsScale, engScale: engScale)
}

}

It looks good in the App, and it is no big deal if it doesn't render as the variables are coded, and the design is fine, however, I removed the @IBDesignable tag and it still errors the same.

Finally, how do I get the UIView to update when I enter the view controller it resided in?

So the questions are;

1 How do I get render to work for this code example?

2 Is there a way to not render the view, and stop the error that way?

3 Do I need to worry about the error as the App runs fine?

4 How do I get the UIView to refresh. What is the syntax for .setNeedsDisplay() etc? I tried lots of things and none updated or reloaded or refreshed.

As always I truly welcome all help, and thank you.

Not sure what version of Xcode you are using. I am using Xcode 6.4.

I, like you, have researched for days on many websites and tried many solutions. None of them worked. At last, I removed the @IBDesignable to my custom UI class. Not only did the error went away, the instance of the custom UI class previewed fine in Main.storyboard.

Perhaps, in the new development of Xcode, @IBDesignable is no longer necessary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM