GraphView.m が UIView の場合performSegueWithIdentifier:sender
、UIViewController メソッドのように、それほど遠くまで到達することはありません。
graphView が viewController から作成されていると仮定すると、そのデリゲートを viewController に設定する必要があります。
GraphView.h で
@interface の上に graphView プロトコルを宣言します。
@protocol GraphViewDelegate
-(void)barPlot:(CPTBarPlot *)plot barWasSelectedAtRecordIndex:(NSUInteger)index
@end
プロパティを宣言します。
@property (weak) id <GraphViewDelegate> delegate;
GraphView.m で:
-(void)barPlot:(CPTBarPlot *)plot barWasSelectedAtRecordIndex:(NSUInteger)index
{
[[self delegate] barPlot:plot barWasSelectedAtRecordIndex:index];
}
ViewController.h で @interface 行を変更します
@interface MyViewController: UIViewController <GraphViewDelegate>
ViewController.m で
graphView を作成するときは、デリゲートを self に設定します (graphView が Interface Builder で作成されている場合は、CTRL キーを押しながら線を viewController にドラッグしてデリゲートを設定できます)。
GraphView* graphView = [GraphView alloc] init];
[graphView setDelegate:self];
GraphView で使用していたデリゲート メソッドを実装します (パラメーターは必要ないかもしれませんが、index
とにかく引き継ぎました)。
-(void)barPlot:(CPTBarPlot *)plot barWasSelectedAtRecordIndex:(NSUInteger)index
{
[self performSegueWithIdentifier:@"list2" sender:self];
}
おそらく、メソッドのシグネチャを次のように変更したいと思うでしょう。
-(void)graphView:(GraphView*)graphView
didSelectBarAtIndex:(NSUInteger)index
barPlot:(CPTBarPlot *)plot
(it's good practice to send a reference to the sender along with the message)