- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我昨天问了这个问题,得到了 Eric Skroch 的大力帮助。然而,在查看了 Core Plot 网站上的所有文档以及一些示例后,我仍然有点困惑。所以我要发布我目前的代码,看看是否有人可以帮助我更多。或许 Eric 也能提供帮助会更容易一些。我的问题是我需要删除一个图,然后在选项卡式应用程序中将其替换为另一个图。 Eric 和其他人说过要使用 reloadData 方法。但是我看不到我可以在代码中的什么地方使用它?这是我的头文件和实现文件。
#import <UIKit/UIKit.h>
#import "CorePlot-CocoaTouch.h"
@interface GraphViewController : UIViewController <CPTPlotDataSource>
@property (nonatomic, strong) CPTGraphHostingView *hostView;
@property (nonatomic, strong) NSMutableArray *myData;
@property (nonatomic) float XAXISMIN;
@property (nonatomic) float XAXISMAX;
@property (nonatomic) float YAXISMIN;
@property (nonatomic) float YAXISMAX;
@property (strong, nonatomic) IBOutlet UILabel *noGraph;
@end
和
#import "GraphViewController.h"
#import "MyVariables.h" // a singleton class for my variables
@interface GraphViewController ()
@end
@implementation GraphViewController
@synthesize hostView = _hostView;
@synthesize myData = _myData;
@synthesize XAXISMIN;
@synthesize XAXISMAX;
@synthesize YAXISMAX;
@synthesize noGraph;
@synthesize YAXISMIN;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[noGraph setText:@""];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
MyVariables *sharedVariables2 = [MyVariables sharedVariables2];
float a = [sharedVariables2.AA floatValue];
MyVariables *sharedVariables3 = [MyVariables sharedVariables3];
float b = [sharedVariables3.BB floatValue];
MyVariables *sharedVariables4 = [MyVariables sharedVariables4];
float c = [sharedVariables4.CC floatValue];
float d = (4.0f)*a*c;
float e = (b*b);
float f = (e - d);
float g = sqrtf(f);
float h = -b;
float i = h + g;
float ii = h - g;
float j = i/(2*a);
float k = ii/(2*a);
// Define x max and min with answers to quad
XAXISMIN = j - (5.0);
XAXISMAX = k + (5.0);
// Find range for the y axis STILL NEEDS WORK!
// maybe if statement for negatives
float z = c - ((b*b)/((4.0f)*a));
YAXISMAX = z + 10.0f;
YAXISMIN = -z;
float inc = (XAXISMAX - XAXISMIN) / 100.0f;
float l = XAXISMIN;
if ((isnan(g)) || (a == 0))
{
[noGraph setText:@"This is not graphable"];
[_hostView setHidden:YES];
}
else
{
NSMutableArray *data = [NSMutableArray array];
for (int i = 0; i < 100; i ++)
{
float y = (a * (l*l)) + (b * l) + c;
NSString *str4 = [NSString stringWithFormat:@"%.3f", l];
NSString *str5 = [NSString stringWithFormat:@"%.3f", y];
NSLog(@"Our X and Y are : %@, %@", str4, str5);
[data addObject:[NSValue valueWithCGPoint:CGPointMake(l, y)]];
l = l + inc;
}
self.myData = data; // put that data array into the array you synthesized
[self initPlot];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)viewDidUnload
{
[self setNoGraph:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
{
return [_myData count];
}
- (NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex: (NSUInteger)index
{
if ([plot.identifier isEqual:@"Your data"])
{
NSValue *value = [self.myData objectAtIndex:index];
CGPoint point = [value CGPointValue];
// FieldEnum determines if we return an X or Y value.
if (fieldEnum == CPTScatterPlotFieldX)
{
return [NSNumber numberWithFloat:point.x];
}
else // Y-Axis
{
return [NSNumber numberWithFloat:point.y];
}
}
return [NSNumber numberWithFloat:0];
}
- (void)initPlot
{
[self configureHost];
[self configureGraph];
[self configurePlots];
[self configureAxes];
}
- (void)configureHost
{
self.hostView = [(CPTGraphHostingView *) [CPTGraphHostingView alloc] initWithFrame:self.view.bounds];
self.hostView.allowPinchScaling = YES;
[self.view addSubview:self.hostView];
}
- (void)configureGraph
{
// 1 - Create graph
CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:self.hostView.bounds];
self.hostView.hostedGraph = graph;
// 2 - Set graph title
NSString *title = @"Your Quadratic";
graph.title = title;
// 3 - Create and set text style
CPTMutableTextStyle *titleStyle = [CPTMutableTextStyle textStyle];
titleStyle.color = [CPTColor whiteColor];
titleStyle.fontName = @"Helvetica-Bold";
titleStyle.fontSize = 16.0f;
graph.titleTextStyle = titleStyle;
graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop;
graph.titleDisplacement = CGPointMake(0.0f, 10.0f);
// 4 - Set padding for plot area
[graph.plotAreaFrame setPaddingTop:30.0f];
[graph.plotAreaFrame setPaddingRight:30.0f];
[graph.plotAreaFrame setPaddingLeft:30.0f];
[graph.plotAreaFrame setPaddingBottom:30.0f];
// 5 - Enable use interaction for plot space
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.allowsUserInteraction = YES;
}
- (void)configurePlots
{
// 1 - Get graph and plot spaces and set axis
CPTGraph *graph = self.hostView.hostedGraph;
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
float xAxisMin = XAXISMIN;
float xAxisMax = XAXISMAX;
float yAxisMin = YAXISMIN;
float yAxisMax = YAXISMAX;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(xAxisMin) length:CPTDecimalFromFloat(xAxisMax - xAxisMin)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(yAxisMin) length:CPTDecimalFromFloat(yAxisMax - yAxisMin)];
// 2 - Create the plot
CPTScatterPlot *quadGraph = [[CPTScatterPlot alloc] init];
quadGraph.dataSource = self;
quadGraph.identifier = @"Your data";
CPTColor *quadColor = [CPTColor blackColor];
[graph addPlot:quadGraph toPlotSpace:plotSpace];
// 4 - Create styles and symbols
CPTMutableLineStyle *quadLineStyle = [quadGraph.dataLineStyle mutableCopy];
quadLineStyle.lineWidth = 2.5;
quadLineStyle.lineColor = quadColor;
quadGraph.dataLineStyle = quadLineStyle;
CPTMutableLineStyle *quadSymbolLineStyle = [CPTMutableLineStyle lineStyle];
quadSymbolLineStyle.lineColor = quadColor;
CPTPlotSymbol *quadSymbol = [CPTPlotSymbol ellipsePlotSymbol];
quadSymbol.fill = [CPTFill fillWithColor:quadColor];
quadSymbol.lineStyle = quadSymbolLineStyle;
quadSymbol.size = CGSizeMake(6.0f, 6.0f);
quadGraph.plotSymbol = quadSymbol;
}
- (void)configureAxes
{
// 1 - Create styles
CPTMutableTextStyle *axisTitleStyle = [CPTMutableTextStyle textStyle];
axisTitleStyle.color = [CPTColor whiteColor];
axisTitleStyle.fontName = @"Helvetica-Bold";
axisTitleStyle.fontSize = 12.0f;
CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle];
axisLineStyle.lineWidth = 2.0f;
axisLineStyle.lineColor = [CPTColor whiteColor];
CPTMutableTextStyle *axisTextStyle = [[CPTMutableTextStyle alloc] init];
axisTextStyle.color = [CPTColor whiteColor];
axisTextStyle.fontName = @"Helvetica-Bold";
axisTextStyle.fontSize = 11.0f;
CPTMutableLineStyle *tickLineStyle = [CPTMutableLineStyle lineStyle];
tickLineStyle.lineColor = [CPTColor whiteColor];
tickLineStyle.lineWidth = 2.0f;
CPTMutableLineStyle *gridLineStyle = [CPTMutableLineStyle lineStyle];
tickLineStyle.lineColor = [CPTColor blackColor];
tickLineStyle.lineWidth = 1.0f;
// 2 - Get axis set
CPTXYAxisSet *axisSet = (CPTXYAxisSet *) self.hostView.hostedGraph.axisSet;
// 3 - Configure x-axis
CPTAxis *x = axisSet.xAxis;
x.title = @"X Axis";
x.titleTextStyle = axisTitleStyle;
x.titleOffset = 1.0f;
x.axisLineStyle = axisLineStyle;
x.labelingPolicy = CPTAxisLabelingPolicyEqualDivisions; //CPTAxisLabelingPolicyNone;
x.labelTextStyle = axisTextStyle;
x.majorTickLineStyle = axisLineStyle;
x.majorTickLength = 4.0f;
x.tickDirection = CPTSignPositive; //CPTSignNegative;
// 4 - Configure y-axis
CPTAxis *y = axisSet.yAxis;
y.title = @"Y Axis";
y.titleTextStyle = axisTitleStyle;
y.titleOffset = -40.0f;
y.axisLineStyle = axisLineStyle;
y.majorGridLineStyle = gridLineStyle;
y.labelingPolicy = CPTAxisLabelingPolicyEqualDivisions;
y.labelTextStyle = axisTextStyle;
y.labelOffset = 16.0f;
y.majorTickLineStyle = axisLineStyle;
y.majorTickLength = 4.0f;
y.minorTickLength = 2.0f;
y.tickDirection = CPTSignNegative;
}
@end
所以我希望有人能让我知道在哪里清除我的数据/图表,这样我一次在图表选项卡上只有一张图表。提前致谢!
最佳答案
您应该在 -viewDidLoad
中初始化和配置图形和托管 View (即调用 -initPlot
),以便它只发生一次。在 -viewDidAppear
中,执行您需要的任何数据处理,为图表做好准备,然后调用 -reloadData
。
关于ios - Core Plot 1.0如何实现reloadData方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12133332/
我正在制作一个应用程序,使用 Flickr 和 Imgur 的 API 提取图像。填充存储图像 URL 和图像标题的模型后,我想重新加载 UI,以便图像填充 collectionview,但是当它被调
出于某种原因[tView reloadData] (其中 tView 是 UITableView)不会刷新我的 UITableView。 cellForRowAtIndexPath , numberO
我正在更新我的表数据资源,然后我打电话 [self.tableView reloadData] 用这个新数据加载 TableView 。这一切都发生在一个线程中。现在,它可以正常工作,假设我添加了 4
我有一个 UICollectionViewCell: “渐变 View ”是具有渐变的 UIView: 数据来源是CoreData。在 Collection View 上,我有对 CoreData 进
我是一名新手 iOS 程序员,正在开发我的第一个应用程序,但遇到了一个小问题。我想在通过网络下载一些数据后更新我的 tableView,并在其 Controller 中使用以下代码来执行此操作: -(
我的应用程序包含两个 collectionView , mainCollectionView 和 nestedCollectionView ,位于 mainCollectionViewCell 中。
我是整个 iOS 开发的新手,所以不是很擅长。我目前有一个带有两个 TableView 的 viewController。第一个表始终可见并包含类别。只有在选择第一个表中的单元格时,第二个表才应该可见
我明白我需要在调用reloadData之前更改数据源中的数据。我的问题是我不确定这是如何完成的以及为什么我的 getData 方法不会覆盖当前单元格。是否有必要为此使用 subview ?或者有没有办
我有一个 4 行的分组 tableView。我对我在两个 View 之间做事的方式进行了大修,现在 reloadData 表现得很奇怪。它只会刷新一行中的数据。 (最后一个)和其他人都没有。 我已经在
当我实例化第三个单元格时,我会将更多项目添加到我的模型数组中,然后我将更新 Collection View 数据: DispatchQueue.main.async(execute: { s
所以,我遇到了麻烦 - 无法重新加载 TableView 的数据,在命令行中我看到了良好的数据 - 当我单击按钮时 idMeet 已更改,但在模拟器中我没有看到刷新 TableView 单击按钮后,i
我正在尝试从 firebase 获取数据并传递给 tableview。 // Model import UIKit import Firebase
我有 2 个类,classA 和 classB在 classA 中,我有一个可以按需工作和刷新的 TableView 。所有的委托(delegate)和数据源都很好,还有一个属性 @property
所以看起来 Swift 中的 TableView 会根据滚动位置动态地将数据重新加载到屏幕上。但是,在我的例子中,我不希望该机制以这种方式工作,因为我的 TableView 中的项目会更新用户订单的总
所以我有一个 tableView,其中有一个标题元素和一些单元格。我正在从服务器中提取单元格,然后在完成后重新加载 tableview。好吧,这至少是现在的目标我在每次追加到数组后重新加载 tavle
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
我想知道 tableView 上的 reloadData 有多贵。我想每 5 秒刷新一次表格 View 。这会导致任何性能问题吗? 最佳答案 重新加载数据将调用 TableView 数据源上的两个主要
在我的应用程序中,我有一个标签,通知用户缺少一些设置: 设置在: override func tableView(_ tableView: UITableView, cellForRowAt inde
在 UITableView 上调用 reloadData 时实际调用了哪些方法? [tableView reloadData]; 最佳答案 整个 TableView 被重新加载,它调用 cellFor
我遇到这样一种情况,代码更改其 collectionView 数据源,然后多次调用 reloadData(),我认为这会导致我的应用程序因竞争条件而崩溃,因为数据源变化非常快,所以我用 Dispatc
我是一名优秀的程序员,十分优秀!