【问题标题】:CPTGraphHostingView in a UIViewUIView 中的 CPTGraphHostingView
【发布时间】:2011-10-04 09:41:23
【问题描述】:

我对上次在这里提问时得到的答案印象深刻,真的很感激。

Core Plot 有这个问题。 我想在我的 UIView 中有一个 CPTGraphHostingView,这样我就可以在它下面有标签和滚动视图之类的东西。

顺便说一下,我正在使用 XCode 3.2。

如何以编程方式执行此操作?或者如果可能的话,使用界面生成器。(我需要详细说明,因为我对这类事情有点陌生) 感谢您的支持。

【问题讨论】:

  • 您不能在 Interface Builder 中现有的 UIView 中添加一个新的自定义 UIView,并将 CPTGraphHostingView 作为其类吗?
  • 你会这么认为......但不幸的是,没有。我遇到了很多错误,应用程序只是崩溃了,所以我想知道是否会有所作为。可能不是。如果您认为可以解决,我会通过过去的 bin 发布错误...

标签: iphone objective-c iphone-sdk-3.0 ios4 core-plot


【解决方案1】:

如果您想将核心绘图图添加到 UIView,您必须将 CPTGraphHostingView 作为子视图添加到 UIView。在下面的示例中,hostingView 是 UIView,graphObject 是 CPTXYGraph。

CPTGraphHostingView *graphHostingView = [[CPTGraphHostingView alloc] initWithFrame:hostingView.bounds];

[hostingView addSubview:graphHostingView];

graphHostingView.hostedGraph = graphObject;

【讨论】:

  • let graphHostingView = CPTGraphHostingView(frame: hostingView.bounds) hostingView.addSubview(graphHostingView) graphHostingView.hostedGraph = graphObject 在 Swift 中
【解决方案2】:

简单地将 CPTGraphHostingView 添加为 UIView 的子视图 [以编程方式] 对我不起作用。

我搜索了许多线程,最后我尝试了最简单的方法 - 我在界面生成器中创建了新的 UIView,在这个视图中我创建了另一个 UIView 并将其更改为 CPTGraphHostingView。现在我可以简单地创建图表 [就像在教程中一样] 并将其主 UIView 链接到我想要的任何位置。

我不知道为什么这不能以编程方式工作,但它可以在 Interface Builder 中工作。

我使用 Xcode 4.2Core plot 1.0

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多