【问题标题】:Core-Plot inside a UICollectionViewCellUICollectionViewCell 中的核心绘图
【发布时间】:2018-09-07 00:00:23
【问题描述】:

我有一个UICollectionView,其中一个单元格内有一个核心图。

UIView 中制作 Core-Plot 图表时我没有任何问题,但我无法让此 Core-Plot 图表在 UICollectionViewCell 中工作。

在 MyCollectionViewCell.swift 中

import UIKit
import CorePlot

class MyCollectionViewCell: UICollectionViewCell {
    @IBOutlet weak var corePlot: CPTGraphHostingView!
}

在 MyViewController.swift 中

import UIKit
import CorePlot

class MyViewController: UIViewController,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {

...

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let theCell = collectionView.dequeueReusableCell(withReuseIdentifier: "MyCollectionViewCell", for: indexPath) as! MyCollectionViewCell
        let graph = CPTXYGraph(frame: theCell.corePlot.bounds)
        theCell.corePlot.hostedGraph = graph // This is where it crashes
        ...
    }

...

}
extension MyViewController: CPTScatterPlotDataSource, CPTScatterPlotDelegate {
    ...
}

-[UIView setHostedGraph:]:无法识别的选择器发送到实例 0x7f8a9aa20240

*** 由于未捕获的异常 'NSInvalidArgumentException' 导致应用程序终止,原因:'-[UIView setHostedGraph:]: unrecognized selector sent to instance 0x7f8a9aa20240'

【问题讨论】:

    标签: ios swift uicollectionview core-plot


    【解决方案1】:

    你需要将类名CPTGraphHostingView设置为corePlot

    @IBOutlet weak var corePlot: CPTGraphHostingView!
    

    在 IB 中的 xib 文件/单元原型中,这里是 UIView in crash

    [UIView setHostedGraph:]

    表示你没有分配它

    【讨论】:

    • 感谢您的快速回复。我是 Swift 新手,所以我没有使用 xib 文件的经验。所以你说我应该创建一个自定义 xib 文件,并将 UIView 添加为 xib 文件的所有者,然后将视图添加为 UIView 文件中的 IBOutlet。
    • 您有单独的 xib 用于单元格或 IB 内集合上方的原型单元格吗?我的意思是你在哪里分配 MyCollectionViewCell 你应该为上述视图设置类名
    • 不确定我是否完全理解。当我创建我的单元格时,我是在 Storyboard 中完成的。然后我用 UIView 填充单元格。我将 UIView 连接为 MyCollectionViewCell 中的 CPTGraphHostingView。然后在 MyViewController 中的 cellForItemAt 函数中,我尝试访问它以便创建图表。
    • 在单元格内选择该视图,并在身份检查器中为其设置类名
    • 太棒了。你是山羊。
    猜你喜欢
    • 1970-01-01
    • 2013-05-21
    • 1970-01-01
    • 2014-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多