访问另一个类的方法
我是 C 目标的新手,遇到了很多困难。希望各位大佬能够帮帮我。
好吧,我有一个视图控制器类,它显示来自插入 iPhone 的外部传感器的数据。我有另一个数据库类,它应该获取该数据并将其存储在一个可用于绘制图表的数组中。
我很难找到一种方法来捕获视图控制器类方法变量捕获的数据并将其存储在数据库类中。
下面的代码来自 View Controller 类,它捕获模拟信号并显示在 UILabel 中。
(void) forceCalculationKg{
NSNumber *number = [controller. analogInValues objectAtIndex:0];
[controller enableDigitalInputs:YES];
double value = [number doubleValue];
double force;
force = 0.2908 *pow(2.718,(1.2089 * value));
double forcekg;
forcekg = force/2.2;
forceoutput.text = [NSString stringWithFormat:@" %0.1f", forcekg];
}
I am new to the C objective and I'm having lots of difficulties. Hope you goys would be able to help me out.
Alright, I have a view controller class that displays the data from the external sensor plugged to an iphone. I have another database class that is supposed to grab that data and store it in an array which can be used to plot a graph.
I'm having difficulties in finding a way to capture the data captured by the view controller class method variables and using it to store in database class.
The code below is from View Controller class which captures analog signal and displays in UILabel.
(void) forceCalculationKg{
NSNumber *number = [controller. analogInValues objectAtIndex:0];
[controller enableDigitalInputs:YES];
double value = [number doubleValue];
double force;
force = 0.2908 *pow(2.718,(1.2089 * value));
double forcekg;
forcekg = force/2.2;
forceoutput.text = [NSString stringWithFormat:@" %0.1f", forcekg];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有为这个问题提交实际编译的代码。但无论如何,我假设您的 forceCalculationKg 方法是您调用以检索传感器数据的控制器上的函数?然后,您对数据进行计算并显示它,对吧?要保留这些数据,只需将 NSMutableArray 属性添加到控制器并将每个转换后的数据点保存到其中即可。
其中
datapoints
是 NSMutableArray 通过 @property 和 @synthesize 关键字添加到视图控制器的属性。然后,您可以将程序中的datapoints
数组传递到您需要的任何地方。You didn't submit code for this question that actually compiles. But in any case, I assume your forceCalculationKg method is the function on your controller that you are calling to retrieve the sensor data? You are then applying a calculation to the data and displaying it, right?. To keep this data around, just add a NSMutableArray property to your controller and save each transformed data point to it.
Where
datapoints
is a NSMutableArray property you add to your view controller via the @property and @synthesize keywords. You can then pass thedatapoints
array around your program to wherever you need it.