Reputation: 4235
I must use s7graphview
library for draw simple histogram, and I've got custom function called
-(IBAction)histogram:(id)sender;
. in this function every pixel from image is passed to array as RGB representation. then pixels are counted and I've got red, green and blue array. I can send to NSLog or something but problem is, when I try to send 3 arrays to - (NSArray *)graphView:(S7GraphView *)graphView yValuesForPlot:(NSUInteger)plotIndex;
. both functions are in the same .m file, and I have no idea how to pass data between them, because when I write redArray, Xcode don't suggest me this name.
Upvotes: 0
Views: 261
Reputation: 3208
Since - (NSArray *)graphView:(S7GraphView *)graphView yValuesForPlot:(NSUInteger)plotIndex
is a delegate method, it should be implemented in your class that is posing as a delegate to S7GraphView
object. You don't call explicitly, you define it as such in your .m implementation:
- (NSArray *)graphView:(S7GraphView *)graphView yValuesForPlot:(NSUInteger)plotIndex
{
if ( plotIndex == <some index value> )
return redArray;
else
return nil;
}
I have no idea what plotIndex
corresponds with your various color arrays, but you should get the idea.
When the S7GraphView
object needs that data, it will invoke that delegate
method.
This is not unlike implementing UITableViewDelegate
and UITableViewDataSource
methods. When a UITableView
method -reloadData
is invoked, it will call upon your view controller (presuming it is delegate/data source of the table) to supply UITableViewCell
objects via
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = <... dequeue or created ... >.
/*
do some cell set up code based on indexPath.section and indexPath.row
*/
return cell;
}
Similar with S7GraphView
I'm sure (I don't have the API to see all it does). In your IBAction
method, you will probably be doing something like:
- (IBAction)histogram:(id)sender
{
// maybe you recalculate your red, green, and blue component arrays here and cache
// or maybe you calculate them when requested by the delegate method
// tell the S7GraphView it needs to update
// (not sure what the reload method is actually called)
[self.myS7GraphView reloadGraph];
}
Upvotes: 1