看板 MacDev 關於我們 聯絡資訊
※ 引述《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 請問大家這要怎麼解決呢?十分感謝!!!! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.114.14.138 ※ 文章網址: https://www.ptt.cc/bbs/MacDev/M.1448019662.A.FBE.html
darktt: 你要用if let graphView = self.graphView {} 來避免 gr 11/20 20:18
darktt: XaphView 是 nil 的情況 11/20 20:18
ray3518i: darktt大,但我加上判斷式之後,裡面的內容就不會執行了 11/20 20:29
ray3518i: 是不是我用MainController().plot這個方法不對? 11/20 20:30
darktt: 你用的曲線圖的Code也太老了,建議改用JBChartView 11/21 07:06
gradyzhuo: 請去查一下ViewController怎麼用還有怎麼跟Storyboard 11/26 20:05
gradyzhuo: 戶動 之類的,只能說,你的需求,MainViewController() 11/26 20:05
gradyzhuo: 直接就是不對的 11/26 20:05