本文介绍了错误:“ - [UIView setHostedGraph:]:无法识别的选择器”在iPhone应用程序中执行核心情节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试编译以下代码时出现以下错误:

I get the below error when I try to compile the below code:

代码:

 UIView *ChartView;

  ChartView = [[UIView alloc] init];
  graph = [[CPXYGraph alloc] initWithFrame: ChartView.bounds];

CPGraphHostingView *hostingView = (CPGraphHostingView *)ChartView;
hostingView.hostedGraph = graph;

可能出现什么问题?

推荐答案

你正在施放 UIView 实例(回应 -setHostedGraph :)到 CPGraphHostingView 。 - 这将工作。

You're casting a UIView instance (which does not respond to -setHostedGraph:) to a CPGraphHostingView. - This will not work.

您需要创建一个实际的 CPGraphHostingView 对象,然后在其上调用 -setHostedGraph:

You'll need to create an actual CPGraphHostingView object, then invoke -setHostedGraph: on it.

所以,你的代码应该看起来像这样:

So, your code should look like this:

CGRect someFrame = ...;
CPGraphHostingView *hostingView = [[CPGraphHostingView alloc] initWithFrame:someFrame];
graph = [[CPXYGraph alloc] initWithFrame: hostingView.bounds];

hostingView.hostedGraph = graph;

这篇关于错误:“ - [UIView setHostedGraph:]:无法识别的选择器”在iPhone应用程序中执行核心情节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 02:34