楼主:
ray3518i (RAY3518I)
2015-11-20 19:40:57※ 引述《ray3518i (RAY3518I)》之铭言:
: 大家好, 我是刚接触iOS使用Swift开发不到半年的新手
: 为了研究的需要目前正在写一个透过蓝牙收取sensor资料并分析的app
: 由于没有什么程式设计的背景, 所以有些观念不是非常的了解
: 因此想请问大家
: 目前我已经可以透过蓝牙收到sensor所传送的data
: 若我想将收到的值传到UIView里的drawrect方法, 做即时性的曲线绘图应该要怎么做呢?
: 绘图的部分我几乎都是参照网络上的教学, 但似乎都是在读取View时就将图案画出来
: 虽然有看到一个setNeedsDisplay的方法, 但还是不太知道怎么使用...
: 还请麻烦大家帮我解惑!
: 非常感谢!
谢谢大家的回应,目前我是使用了CorePlot去绘图
目前遇到了绘图上的一些问题...
由于我的收data指令和画图是写在不同的class当中
当我在BluetoothManager的class中要呼叫MainController的画图function时
我的程式码如下
class BluetoothManager: NSObject {
func dataReceiving(value: [Int]){
for (var m=0 ; m<5 ; m++){
dataOne[m] = value[2*m]
dataTwo[m] = value[2*m+1]
}
MainController().plot(dataOne: [Int], dataTwo: [Int])
}
class MainController: UIViewController,CPTScatterPlotDataSource {
@IBOutlet weak var graphView: CPTGraphHostingView!
private var scatterGraph : CPTXYGraph? = nil
typealias plotDataType = [CPTScatterPlotField : Double]
private var dataForPlot = [plotDataType]()
func plot(dataOne: [Int], dataTwo: [Int]){
let newGraph = CPTXYGraph(frame: CGRectZero)
graphView.hostedGraph = newGraph
...
}
}
在执行到 graphView.hostedGraph = newGraph 时
就会出现fatal error: unexpectedly found nil while unwrapping an Option Value
请问大家这要怎么解决呢?十分感谢!!!!
作者: gradyzhuo 2015-11-26 20:05:00
请去查一下ViewController怎么用还有怎么跟Storyboard户动 之类的,只能说,你的需求,MainViewController()直接就是不对的