访问另一个类的方法

发布于 2024-11-27 15:13:12 字数 630 浏览 2 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神魇的王 2024-12-04 15:13:12

您没有为这个问题提交实际编译的代码。但无论如何,我假设您的 forceCalculationKg 方法是您调用以检索传感器数据的控制器上的函数?然后,您对数据进行计算并显示它,对吧?要保留这些数据,只需将 NSMutableArray 属性添加到控制器并将每个转换后的数据点保存到其中即可。

-(void) forceCalculationKg { 
     NSNumber *number = [controller.analogInValues objectAtIndex:0]; 
     [controller enableDigitalInputs:YES];  
     double value = [number doubleValue]; 
     double force = 0.2908  *pow(2.718,(1.2089 * value)); 
     double forcekg = force/2.2;
     [self.datapoints addObject: [NSNumber numberWithDouble: forcekg]];
     forceoutput.text = [NSString stringWithFormat:@" %0.1f", forcekg]; 
} 

其中 datapointsNSMutableArray 通过 @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.

-(void) forceCalculationKg { 
     NSNumber *number = [controller.analogInValues objectAtIndex:0]; 
     [controller enableDigitalInputs:YES];  
     double value = [number doubleValue]; 
     double force = 0.2908  *pow(2.718,(1.2089 * value)); 
     double forcekg = force/2.2;
     [self.datapoints addObject: [NSNumber numberWithDouble: forcekg]];
     forceoutput.text = [NSString stringWithFormat:@" %0.1f", forcekg]; 
} 

Where datapoints is a NSMutableArray property you add to your view controller via the @property and @synthesize keywords. You can then pass the datapoints array around your program to wherever you need it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文