-1

Using the code below in coreplot(Barchart) to perform segue from GraphView.m class

but I get an error: instance method '-performSegueWithIdentifier:sender:' not found (return type defaults to 'id')

How do I fix it ? Please Help .
Thanks in Advance.

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

         [self performSegueWithIdentifier:@"list2" sender:self];
    }
Jacob Wood
  • 467
  • 9
  • 26

2 Answers2

1

If GraphView.m is a UIView you won't get very far, as performSegueWithIdentifier:sender is a UIViewController method.

Assuming that graphView is created from a viewController, you want to set it's delegate to the viewController.

in GraphView.h

  • declare a graphView protocol above your @interface:

    @protocol GraphViewDelegate
    -(void)barPlot:(CPTBarPlot *)plot barWasSelectedAtRecordIndex:(NSUInteger)index
    @end

  • declare a property:

    @property (weak) id <GraphViewDelegate> delegate;

in GraphView.m:

-(void)barPlot:(CPTBarPlot *)plot barWasSelectedAtRecordIndex:(NSUInteger)index
    {
        [[self delegate] barPlot:plot barWasSelectedAtRecordIndex:index];
    } 

in ViewController.h modify the @interface line

@interface MyViewController: UIViewController <GraphViewDelegate>

in 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)
foundry
  • 31,615
  • 9
  • 90
  • 125
  • Graphview is just a class .So How do I **performSegueWithIdentifier:sender** within the method shown above? – Jacob Wood Jan 15 '13 at 11:04
  • You really want to be sending it to your viewController - better still, use a delegate to message the viewController - does that make sense from the perspective of GraphView? – foundry Jan 15 '13 at 11:06
  • How to do that? Please help. – Jacob Wood Jan 15 '13 at 11:07
  • Is there a UIViewController that creates the graphView? – foundry Jan 15 '13 at 11:07
  • Thank You Sir. I tried **TargetViewController *targetVC = (TargetViewController*)segue.destinationViewController; targetVC.string1 = string1;** as suggested by Mr.Prajwal and its still not working. – Jacob Wood Jan 15 '13 at 11:15
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/22740/discussion-between-jacob-wood-and-he-was) – Jacob Wood Jan 15 '13 at 11:46
0

the method is not found you can try also including that method in .h file if you are sure that you have not made any spelling mistake.

Prajwal Udupa
  • 860
  • 5
  • 28
  • I have not made any spelling mistake.Its a class I am trying to call performSegueWithIdentifier:sender inside the method in that class How do I do that ? – Jacob Wood Jan 15 '13 at 11:06
  • may this would help [link](http://stackoverflow.com/questions/9176215/understanding-performseguewithidentifier) – Prajwal Udupa Jan 15 '13 at 11:09