简体   繁体   English

使用@IBDesignable在Swift中渲染UIView,崩溃

[英]Rendering UIView in Swift with @IBDesignable, crash

I have a graph built in Paintcode that I am showing in a UIView. 我有一个在Paintcode中构建的图形,该图形显示在UIView中。 It works fine in the App but will not render in storyboard. 它在App中运行正常,但不会在情节提要中呈现。 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. 该图采用14个变量来生成条形图。 Here is the class code 这是课程代码

import UIKit 导入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. 它在App中看起来不错,并且如果不对它进行渲染(因为已对变量进行编码)也没什么大不了的,而且设计还不错,但是,我删除了@IBDesignable标记,并且仍然会出现相同的错误。

Finally, how do I get the UIView to update when I enter the view controller it resided in? 最后,当我进入驻留的视图控制器时,如何更新UIView?

So the questions are; 问题是;

1 How do I get render to work for this code example? 1如何使渲染适用于此代码示例?

2 Is there a way to not render the view, and stop the error that way? 2有没有一种方法可以不渲染视图并以这种方式停止错误?

3 Do I need to worry about the error as the App runs fine? 3当应用运行正常时,我是否需要担心该错误?

4 How do I get the UIView to refresh. 4如何使UIView刷新。 What is the syntax for .setNeedsDisplay() etc? .setNeedsDisplay()等的语法是什么? 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. 不确定您使用的Xcode版本。 I am using Xcode 6.4. 我正在使用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. 最后,我将@IBDesignable删除到我的自定义UI类中。 Not only did the error went away, the instance of the custom UI class previewed fine in Main.storyboard. 错误不仅消失了,自定义UI类的实例在Main.storyboard中可以很好地预览。

Perhaps, in the new development of Xcode, @IBDesignable is no longer necessary. 也许,在Xcode的新开发中,@ IBDesignable不再需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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