-1

在 coreplot(Bartchart) 中使用下面的代码从 GraphView.m 类执行 segue

但我收到一个错误: 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:senderUIViewController 方法一样。

假设 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

  • when you create the graphView, set the delegate to self (if graphView is created in Interface Builder, you can CTRL-drag a line to the viewController to set the delegate):

    GraphView* graphView = [GraphView alloc] init];
    [graphView setDelegate:self];

  • implement the delegate method as you had it in GraphView (you may not need the index parameter but I carried it over anyway)..

    -(void)barPlot:(CPTBarPlot *)plot barWasSelectedAtRecordIndex:(NSUInteger)index
     {
        [self performSegueWithIdentifier:@"list2" sender:self];
     }
    

You probably want to modify your method signature, to something like

            -(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 回答