-1

以下のコードをcoreplot(Barchart)で使用して、GraphView.mクラスからセグエを実行します

しかし、エラーが発生します: instance method '-performSegueWithIdentifier:sender:' not found (return type defaults to 'id')

どうすれば修正できますか?助けてください 。
前もって感謝します。

-(void)barPlot:(CPTBarPlot *)plot barWasSelectedAtRecordIndex:(NSUInteger)index
    {
        NSLog(@"barWasSelectedAtRecordIndex %d", index);

         [self performSegueWithIdentifier:@"list2" sender:self];
    }
4

2 に答える 2

1

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)
于 2013-01-15T10:59:51.053 に答える
0

メソッドが見つからない場合は、スペルを間違えていないことが確実な場合は、そのメソッドを .h ファイルに含めることもできます。

于 2013-01-15T10:58:17.543 に答える