【发布时间】:2013-02-25 17:53:37
【问题描述】:
我有一个单视图应用程序,其中 ViewController 包含一个自定义类 CPTGraphHostingView 的 UIView,因此它包含一个 CorePlot 图。该 UIView 的内容由名为 SimpleScatterPlot 的 NSObject 子类管理。这个SimpleScatterPlot 对象包含配置图形所需的所有参数(轴范围、标签、点数等)
ViewController.h
#import <UIKit/UIKit.h>
#import "CorePlot-CocoaTouch.h"
#import "SimpleScatterPlot.h"
@interface ViewController : UIViewController
{
IBOutlet CPTGraphHostingView *_graphHostingView;
SimpleScatterPlot *_scatterPlot;
NSMutableData *dataConexion;
}
@property (nonatomic,strong) NSArray *valor;
@property (nonatomic,strong) NSArray *strAnoMes;
@property (nonatomic,strong) NSArray *indicador;
@property (nonatomic, retain) SimpleScatterPlot *scatterPlot;
@end
在 ViewController.m 中,我有一些方法可以从一些 JSON 数据中初始化一些数组:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize indicador,valor,strAnoMes;
- (void)viewDidLoad
{
[super viewDidLoad];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSString *urlString = @"http://xxxx/ios/datosgrafica.php";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
(void)[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
dataConexion = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)theData
{
[dataConexion appendData:theData];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
indicador = [NSJSONSerialization JSONObjectWithData:dataConexion options:nil error:nil];
// ARRAYS OF INTEREST
strAnoMes = [indicador valueForKey:@"StrAnoMes"];
valor = [indicador valueForKey:@"Valor"];
self.scatterPlot = [[SimpleScatterPlot alloc] initWithHostingView:_graphHostingView andData:pointArray];
[self.scatterPlot initialisePlot];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
UIAlertView *errorView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"The download could not complete - please make sure you're connected to either 3G or Wi-Fi." delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[errorView show];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
在SimpleScatterPlot.m中我想使用数组“valor”来配置坐标轴范围,我想使用数组“strAnoMes”在xAxis中绘制自定义标签。
我需要做什么才能将 ViewController 中定义的数组传递给 SimpleScatterPlot?
我曾尝试#import "ViewController.h",但它给了我错误。还有其他想法吗?处理这种情况的最佳方法是什么?
【问题讨论】:
标签: objective-c cocoa-touch nsarray core-plot