Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8753111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:21:52+00:00 2026-06-13T13:21:52+00:00

I’ve been wrestling with this for a few days – I have a custom

  • 0

I’ve been wrestling with this for a few days – I have a custom protocol that is supposed to get the data from one of my models (via it’s controller) to a view that graphs it.

Here’s how I am doing this – step by step:

In graphing view, I declare the protocol as follows:

@class GraphView;

@protocol GraphViewDataSource <NSObject>

-(CGFloat)yValueForGraphView:(GraphView *)sender usingXval:(CGFloat)xVal;

@end

I then declare a property in view.h

@interface GraphView : UIView

@property (nonatomic, weak) IBOutlet id <GraphViewDataSource> dataSource;

@end

I synthesize the property in view.m:

@synthesize dataSource=_dataSource;

Then in my drawRect, I am calling this method to bring me back a CGFloat from another controller’s model:

-(void) drawRect:(CGRect)rect
{
//context stuff, setting line width, etc

CGPoint startPoint=CGPointMake(5.0, 6.0);

NSLog(@"first, y value is: %f", startPoint.y);

startPoint.y=[self.dataSource yValueForGraphView:self usingXval:startPoint.x]; //accessing delegate via property

NSLog(@"now the y value now is: %f", startPoint.y);

//other code..
}

Now in my other view controller, I am importing the view.h file and declaring that it conforms to the protocol:

#import "GraphView.h"

@interface CalculatorViewController () <GraphViewDataSource>

Creating a property for the GraphView:

@property (nonatomic, strong) GraphView *theGraphView;

Synthesize:

@synthesize theGraphView=_theGraphView;

Now in the setter, I set the current controller as the dataSource (aka the delegate):

-(void) setTheGraphView:(GraphView *)theGraphView
{
    _theGraphView=theGraphView;
    self.theGraphView.dataSource=self;

}

I also set the controller as the delegate in prepareForSegue (one of the things I tried while looking for a fix):

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"GraphViewController"])
    {
        self.theGraphView.dataSource=self;
    }
}

Finally, I implement the required method:

-(CGFloat)yValueForGraphView:(GraphView *)sender usingXval:(CGFloat)xVal
{
    CGFloat test=51.40; //just to test
    return test;
}

And the output I’m getting from my test NSLog in graphView’s drawRect is:

2012-10-25 20:56:36.352 ..[2494:c07] first, y value is: 6.000000
2012-10-25 20:56:36.354 ..[2494:c07] now the y value now is: 0.000000

This should be returning 51.40 via the dataSource, but it is not. I can’t figure out why! Driving me crazy, it seems like I’ve done everything right. But the delegate method is not getting called.

Is there some silly thing I am missing?


Additional info – diagram of controllers & GraphView:

GraphingCalc

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:21:53+00:00Added an answer on June 13, 2026 at 1:21 pm

    The way I solved this was chaining some delegates, my GraphView declares a protocol GraphViewDelegate with the following methods:

    -(float)ordinateForAbscissa:(float)abscissa forGraph:(GraphView *)requestor;
    -(float)scaleForGraph(GraphView *)requestor;
    

    This protocol is implemented by the GraphViewController and he sets himself as a delegate of the GraphView when the controller loads in viewDidLoad.

    Now I have another delegate that is CalculatorControllerDelegate that implements yCoordinateForX that is called from ordinateForAbscissa. CalculatorViewController implements this protocol and when segueing sets itself up as the GraphViewController‘s delegate.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.