我有一个单视图应用程序,其中 ViewController 包含一个自定义类的 UIView,CPTGraphHostingView
以便它拥有一个 CorePlot 图。该 UIView 的内容由名为 的 NSObject 子类管理SimpleScatterPlot
。该SimpleScatterPlot
对象包含配置图形所需的所有参数(轴范围、标签、点数等)
视图控制器.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"
但它给了我错误。还有其他想法吗?处理这种情况的最佳方法是什么?