0

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Tomasz Szulc
  • 4,217
  • 4
  • 43
  • 79
  • Xcode doesn't always prompt you (correctly). If this is your own function you can add more parameters for passing in more data. (By the way, your post is virtually unintelligible -- your question is unclear at best.) – Hot Licks Dec 06 '11 at 17:01
  • `- (NSArray *)graphView:(S7GraphView *)graphView yValuesForPlot:(NSUInteger)plotIndex;` isn't my function. it's delegate function. – Tomasz Szulc Dec 06 '11 at 17:13
  • You need to find a way to allow that delegate method to see your three arrays. Have you tried making your three arrays into ivars and accessing them from within that graphView delegate method? – Tim Dec 06 '11 at 19:06
  • If you wrote the code, you can have your implementation access, eg, properties that were set separately. – Hot Licks Dec 06 '11 at 19:33

1 Answers1

1

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];
}
gschandler
  • 3,208
  • 16
  • 16