开发者

Accessing methods from another class

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 开发者_StackOverflow中文版forcekg;
     forcekg = force/2.2;
     forceoutput.text = [NSString stringWithFormat:@" %0.1f", forcekg];
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜