2011-12-06 43 views
0

我必须使用s7graphview库来绘制简单的直方图,并且我已经有了一个名为 -(IBAction)histogram:(id)sender;的自定义函数。在这个函数中,图像中的每个像素都以RGB表示的形式传递给数组。然后计算像素,我有红色,绿色和蓝色的数组。我可以发送到NSLog或什么东西,但问题是,当我尝试发送3个阵列到- (NSArray *)graphView:(S7GraphView *)graphView yValuesForPlot:(NSUInteger)plotIndex;。这两个函数都在同一个.m文件中,我不知道如何在它们之间传递数据,因为当我写入redArray时,Xcode不会建议我这个名字。如何在函数之间传递数据(数组)

+0

Xcode并不总是提示您(正确)。如果这是你自己的功能,你可以添加更多的参数来传递更多的数据。 (顺便说一下,你的帖子实际上是无法理解的 - 你的问题最好还是不清楚。) –

+0

' - (NSArray *)graphView:(S7GraphView *)graphView yValuesForPlot:(NSUInteger)plotIndex;'不是我的函数。它是委托功能。 –

+0

您需要找到一种方法来允许该委托方法查看您的三个数组。你有没有尝试将你的三个数组放入ivars并从那个graphView委托方法中访问它们? –

回答

1

由于- (NSArray *)graphView:(S7GraphView *)graphView yValuesForPlot:(NSUInteger)plotIndex是一个委托方法,所以应该在实施在您的班级冒充委托给S7GraphView对象。你不显式调用,您在您的m执行它定义为这样的:

- (NSArray *)graphView:(S7GraphView *)graphView yValuesForPlot:(NSUInteger)plotIndex 
{ 
    if (plotIndex == <some index value>) 
     return redArray; 
    else 
     return nil; 
} 

我不知道什么plotIndex对应与各种颜色的阵列,但你应该明白我的意思。

S7GraphView对象需要该数据时,它将调用该方法delegate

这与实施UITableViewDelegateUITableViewDataSource方法不同。当调用一个UITableView方法-reloadData,它会呼吁您的视图控制器(假定它是表的委托/数据源)通过

- (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; 
} 

类似供应UITableViewCell对象与S7GraphView我相信(我不没有API可以看到它所做的一切)。在您的IBAction方法中,您可能会做类似于:

- (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]; 
} 
+0

感谢您的帮助 –