2011-12-06 44 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

感謝您的幫助 –