iPhone MVC. Need some help with understanding how to correctly pass data from Controller to View - iphone

A little background:
I'm a C# developer starting to mess with the iPhone (have an idea for a simple 2D game). The only MVC programming I've done was for the web (ASP.NET MVC) so although I do have an understanding in MVC, I can't wrap my mind around one thing. Here's an example to illustrate.
Say I have a simple app where all I want to do is display a big circle on the screen. I created a "View Based Application" and it gave me the basic classes to start with:
MVCConfusionAppDelegate
MVCConfusionViewController
Now since I'll be doing some custom drawing (I know I can add a subview and show the circle that way, but this is just a sample of a larger piece) I've added a class called MyCustomView and in Interface Builder set the View of the MVCConfusionViewController to be a MyCustomView.
Now here's the problem. I want to be able to set in code the size of how big the ball on the custom view should be. So I have a property on the MyCusomView like this:
#import <Foundation/Foundation.h>
#interface MyCustomView : UIView {
NSNumber *ballSize;
}
#property(nonatomic,retain)IBOutlet NSNumber *ballSize;
#end
#import "MyCustomView.h"
#implementation MyCustomView
#synthesize ballSize;
-(void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
[[UIColor redColor]set];
float floatValue = [self.ballSize floatValue];
CGRect ballRect = CGRectMake(50.0f, 50.0f,floatValue , floatValue);
CGContextFillEllipseInRect(context, ballRect);
}
#end
Then, here's my MVCConfusionViewController:
#import <UIKit/UIKit.h>
#import "MyCustomView.h"
#interface MVCConfusionViewController : UIViewController {
NSNumber *ballSize;
}
#property(nonatomic,retain)IBOutlet NSNumber *ballSize;
#end
#import "MVCConfusionViewController.h"
#import "MyCustomView.h"
#implementation MVCConfusionViewController
#synthesize ballSize;
- (void)viewDidLoad {
[super viewDidLoad];
MyCustomView *myView = (MyCustomView *)self.view;
myView.ballSize = self.ballSize;
}
And finally, the MVCConfusionAppDelegate:
#import <UIKit/UIKit.h>
#class MVCConfusionViewController;
#interface MVCConfusionAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
MVCConfusionViewController *viewController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet MVCConfusionViewController *viewController;
#end
#import "MVCConfusionAppDelegate.h"
#import "MVCConfusionViewController.h"
#import "MyCustomView.h"
#implementation MVCConfusionAppDelegate
#synthesize window;
#synthesize viewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
viewController.ballSize = [NSNumber numberWithInt:200];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
#end
As you can see, there's an ugly cast in my viewDidLoad method. I was hoping I'd be able to make the connection of the ballSize properties in IB, but it won't let me.
So my question simply is, what's the correct way of passing this data from my view controller to my view without doing that cast? I know I'm missing something fundamental, but I just don't see it. Any help would be greatly appreciated!
EDIT: Here's the source code. http://bit.ly/uKyp9 Maybe someone can have a look and see if I'm doing anything wrong.

Are you trying to connect one IBOutlet (in the controller) to another IBOutlet (in the view)? Unfortunately, I don't think it's that easy :-)
You're also storing the data (ballSize) in the controller and the view.
I'd make MVCConfusionViewController a data source for MyCustomView, and then let MyCustomView ask its datasource for the ballSize, inside the -drawRect: method.
#class MyCustomView;
#protocol MyCustomViewDataSource
- (NSNumber *)ballSizeForMyCustomView:(MyCustomView *)view;
#end
#interface MyCustomView {
id<MyCustomViewDataSource> dataSource;
}
#property (nonatomic, assign) IBOutlet id<MyCustomViewDataSource> dataSource;
#end
#implementation MyCustomView
- (void)drawRect:(CGRect) rect {
if (self.dataSource == nil) {
// no data source, so we don't know what to draw
return;
}
float floatValue = [[self.dataSource ballSizeForMyCustomView:self] floatValue];
// ...
}
#end
In Interface Builder, hook MVCConfusionViewController up to the view's dataSource property. Then implement the protocol:
#interface MVCConfusionViewController : UIViewController <MyCustomViewDataSource> {
[...]
}
[...]
#end
#implementation MVCConfusionViewController
- (NSNumber *)ballSizeForMyCustomView:(MyCustomView *)view {
return self.ballSize;
}
#end
This way your view controller could also be the data source for multiple MyCustomViews, because the protocol method takes a MyCustomView as an argument.
If you need more than one ball, have a look at the UITableViewDataSource and implement similar methods, something like:
-(NSInteger)numberOfBallsInMyCustomView:(MyCustomView *)view;
-(NSNumber *)myCustomView:(MyCustomView *) ballSizeAtIndex:(NSInteger)index;

Your view should already be set in IB, so you can use it as is. If you want to use MyCustomView, you can do it like this:
- (void)viewDidLoad {
[super viewDidLoad];
CGRect frame = CGRectMake(0, 0, 320, 480);
MyCustomView *myView = [[MyCustomView alloc] initWithFrame:frame];
myView.backgroundColor = [UIColor greenColor];
self.view = myView;
[myView release];
CGRect rectangle = CGRectMake(20, 20, 20, 20);
[self.view drawRect:rectangle];
}
I couldn't make your drawing code work, I don't know much about that.

One way to avoid the cast would be to add a separate outlet property for the custom view on the controller, and refer to that instead.
In Interface Builder, make an instance of MyCustomView and drag it into the existing view to make it a subview, then attach it to its own outlet on the controller.

Related

Simple Delegate Between View Controller and UIView Isn't Working

So I am using a simple delegate to access a function from a main view controller when a button is pressed on a subview that is generated as an overlay on top of the main view. For some reason the function that is defined in the source view controller isn't being executed. I have done this 100 times and feel like I am just missing something stupid. Here is the code how come this isn't working?
Source ViewController's.h:
#import <UIKit/UIKit.h>
#import "ProfileSettingsViewController.h"
#import "ImageViewer.h"
#interface ProfileViewController : UIViewController <UITextFieldDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, subViewDelegate>
Source viewController.m:
#import <Parse/Parse.h>
#import <QuartzCore/QuartzCore.h>
#import "ImageViewer.h"
#import "ProfileViewController.h"
#interface ProfileViewController () <UITextFieldDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, subViewDelegate>
#end
//where the ImageViewer object is defined
#implementation ProfileViewController
{
NSMutableArray *dataArray;
ImageViewer *loadImageViewer;
}
//where the UIView is initialized
- (void) handleImageTap:(UIGestureRecognizer *)gestureRecognizer
{
if ([gestureRecognizer view] == _profilePic)
{
loadImageViewer = [ImageViewer alloc];
[loadImageViewer loadImageIntoViewer:self imageToLoad:_profilePic.image];
}
else if ([gestureRecognizer view] == _coverPhoto)
{
}
}
Destination View's.h
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#protocol subViewDelegate
-(void)photoFromSubview:(id)sender;
#end
#interface ImageViewer : UIView
#property (nonatomic, assign) id <subViewDelegate> delegate;
#property (nonatomic, copy) UIImage *mainImage;
#property (nonatomic, copy) UIViewController *parentView;
- (void)fromCameraRoll;
- (void)takePhoto;
- (void)removeImageViewer;
- (void)captureImage:(id)sender;
- (void)uploadPhoto:(id)sender;
- (UIImage *)addBackground;
- (ImageViewer *)loadImageIntoViewer:(UIViewController *)superView imageToLoad:(UIImage *)imageToLoad;
#end
Destination View's.m
#import "ImageViewer.h"
#implementation ImageViewer : UIView
//synthesize properties
#synthesize mainImage = _mainImage;
#synthesize parentView = _parentView;
//initialize the image viewer
- (ImageViewer *)loadImageIntoViewer:(UIViewController *)superView imageToLoad:(UIImage *)imageToLoad
{
//create a new view with the same frame size as the superView
ImageViewer *imageViewer = [[ImageViewer alloc] initWithFrame:superView.view.bounds];
_mainImage = imageToLoad;
_parentView = superView;
//if something's gone wrong, abort!
if(!imageViewer)
{
return nil;
}
//add all components and functionalities to the program
UIImageView *background = [[UIImageView alloc] initWithImage:[imageViewer addBackground]];
background.alpha = 0.85;
[imageViewer addSubview:background];
[imageViewer addSubview:[imageViewer addImageToView:_mainImage superView:superView.view]];
[imageViewer addSubview:[imageViewer addButtonToView:(superView.view.bounds.origin.x + 10.0) yPos:(superView.view.bounds.origin.x + 10.0) buttonAction:#selector(back:) buttonTitle:#"Back"]];
[imageViewer addSubview:[imageViewer addButtonToView:(superView.view.bounds.origin.x + 10.0) yPos:((superView.view.center.y/2) + 270.0) buttonAction:#selector(captureImage:) buttonTitle:#"Camera"]];
[imageViewer addSubview:[imageViewer addButtonToView:(superView.view.bounds.origin.x + 105.0) yPos:((superView.view.center.y/2) + 270.0) buttonAction:#selector(uploadPhoto:) buttonTitle:#"Upload"]];
[imageViewer addSubview:[imageViewer addButtonToView:(superView.view.bounds.origin.x + 200.0) yPos:((superView.view.center.y/2) + 270.0) buttonAction:#selector(rotatePhoto:) buttonTitle:#"Rotate"]];
[superView.view addSubview:imageViewer];
return imageViewer;
}
//call delegate method
- (void)captureImage:(id)sender
{
[self.delegate photoFromSubview:self];
}
I have screwed something up haven't I?
The best way to debug this is to use breakpoints and see what gets invoked, and what doesn't (and check if your delegate is properly set). Of the top of my head, I would say you either forgot the set the delegate or possibly an outlet if you're using IB.
Edit: Ok, It seems to me now that your delegate property is in the wrong class. That property should be in your subview, and when creating that subview from your superview, you should set the delegate properly, something like this:
mySubview.delegate = self;
It looks like in your ProfileViewController.h you are missing a declaration of ImageViewer
#property (nonatomic, weak) ImageViewer *imageViewer;
And in your ProfileViewController.m you need to set the delegate.
self.imageViewer.delegate = self;
You need to set the destination delegate to self.
ImageViewer *imageViewer = [[ImageViewer alloc] initWithFrame:superView.view.bounds];
imageViewer.delegate = self;
When you have a UIView that loads its self after you hace initialized the object and called the load method you set the delegate by using.
imageViewer.delegate = superView;
Where imageView is the newly initialized view not to be confused with the object self (self.delegate = superView isn't the same) and where superView is the is the parent view creating the UIView.
Now my last question would be is there a better way to do what I have done? I feel like I have over complicated the situation.
I am having the exact same problem in exactly same scenario.
After doing some brain storming i found the issue and resolved successfully.
The problem is scope of UIView object. So to resolve this create a global object of view in .h file and use it as your target object.
#interface profilePageViewController : parentViewController<PhotoUploadViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,ConnectionsDelegate>
{
PhotoUploadView *photoUploadView;
And it will work very sure, You can also try to by printing the object to and you will find two different objects.One at time of init and other in delegate call.

How to pass digit or data from subclassed UIView to UIViewController?

I have subclassed UITableViewController and inside table I have custom cells. And this custom cells have subclassed UIView inside. So this UIView is written in its own class. In my code the UITableViewController class is named MainViewController.h/.m and UIView's class is named ContentView.h/.m So in ContentView I added an image and tapGestureRecognizer. To when the image is tapped some date(in this case digit) is send to MainViewController. The first problem is that the delegate method does not get called. And if I call it with notificationCenter it logged it as 0.00000 Can someone help me to pass data from view inside cell to ViewController.
This is my code:
ContentView.h:
#class ContentView;
#protocol ContentViewDelegate
- (void)passDigit:(float)someDigit;
#end
#import <UIKit/UIKit.h>
#import "MainViewController.h"
#interface ContentView : UIView
{
id <ContentViewDelegate> delegate;
float someDigit;
}
#property float someDigit;
#property (assign) id <ContentViewDelegate> delegate;
#end
ContentView.m
#import "ContentView.h"
#implementation ContentView
#synthesize someDigit;
#synthesize delegate;
- (void)handleContentTouch:(UIGestureRecognizer *)gesture
{
someDigit = 134;
[self.delegate passDigit:someDigit];
}
- (void)setupView
{
CGRect frame = self.frame;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(handleContentTouch:)];
UIImageView *fifthBackground = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,100,100)];
[self addSubview:fifthBackground];
[fifthBackground setUserInteractionEnabled:YES];
[fifthBackground addGestureRecognizer:tap];
}
MainViewController.h
#import <UIKit/UIKit.h>
#import "ContentView.h"
#interface MainViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate, ContentViewDelegate>
#end
MainViewContorller.m
#import "MainViewController.h"
#implementation MainViewController
- (void)viewDidLoad
{
[super viewDidLoad];
ContentView *contentView = [[ContentView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
contentView.delegate = self;
}
- (void) passDigit:(float)someDigit
{
NSLog(#"%f",someDigit);
}
Not sure what you are trying to do, may be you are new and learning out some things. Try doing the following:
Change your method in mainViewController
- (void) showDetailViewControllerWithDigit:(float)someDigit
{
NSLog(#"%f",someDigit);
}
to
- (void)passDigit:(float)someDigit
{
NSLog(#"%f",someDigit);
}
and it should work. Also not very relevant here but you have spelled delegate and delegete in two different places. Be mindful that they both will be considered as two different variables. Though not necessary to have an instance variable with the same name, I would definitely not have it with a slight typo, because it will cause a lot of problems later.
When you define a protocol for a delegate, the methods you have defined there should be implemented in the delegate class.
Also in your code you have, obviously you have missed some parts, which show as to where you are adding the contentView in the main view controller. I am assuming that some where you have
[self.view addSubview:contentView];
in the viewDidLoad or some where, without which you cannot even see the contentView and there fore cannot tap it.
Happy coding.

Issue with UIButton Subclass delegate method

Here is the situation. I have a view controller titled "MyViewController." Within this view controller I have a text editing feature that uses subclassed buttons. The name of the UIButton Subclass is "ColorSwatch"
I have setup delegate/protocol methods in the "ColorSwatch.h" subclass as follow.
// ColorSwatch.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
#protocol ColorSwatchDelegate <NSObject>
- (void)fontColor:(UIColor *)color;
#end
#interface ColorSwatch : UIButton {
id <ColorSwatchDelegate> colorSwatchDelegate;
CAGradientLayer *gradient;
UIView *currentView;
UIColor *fontColor;
}
#property (nonatomic, retain) id <ColorSwatchDelegate> colorSwatchDelegate;
#property (nonatomic, retain) CAGradientLayer *gradient;
#property (nonatomic, retain) UIView *currentView;
#property (nonatomic, retain) UIColor *fontColor;
#end
Now in my "ColorSwatch.m" I have:
// ColorSwatch.m
#import "ColorSwatch.h"
#import <QuartzCore/QuartzCore.h>
#import "MyViewController.h"
#implementation ColorSwatch
#synthesize gradient;
#synthesize currentView;
#synthesize colorSwatchDelegate;
#synthesize fontColor;
-(void)setupView{
"Makes the subclassed buttons pretty"
}
-(id)initWithFrame:(CGRect)frame{
if((self = [super initWithFrame:frame])){
}
return self;
}
-(id)initWithCoder:(NSCoder *)aDecoder{
if((self = [super initWithCoder:aDecoder])){
[self setupView];
MyViewController *mvc = [[MyViewController alloc] initWithNibName:
#"MyViewController" bundle:nil];
self.colorSwatchDelegate = mvc;
}
return self;
}
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[self magnify:view];
fontColor = view.backgroundColor;
[self.colorSwatchDelegate fontColor:fontColor];
}
- (void)magnify:(UIView *)view
{
}
- (void)dealloc
{
[currentView release];
[gradient release];
[fontColor release];
[super dealloc];
}
#end
In the "MyViewController.h" I have:
// MyViewController.h
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import "ColorSwatch.h"
#interface MyViewController : UIViewController <ColorSwatchDelegate> {
UITextField *photoLabelTextField;
}
#property (nonatomic, retain) IBOutlet UITextField *photoLabelTextField;
#end
In the "MyViewController.m" I have:
- (void)fontColor:(UIColor *)color
{
NSLog(#"Selected Font Color");
[self.photoLabelTextField setTextColor:color];
}
Now the delegate method sort of works, meaning when I tap on a color button the
NSLog(#"Selected Font Color");
message gets fired. But the problem is that I cannot change the
[self.photoLabelTextField setTextColor:color];
property. I have tried numerous ways of changing the property, the only thing that I can do is send NSLogs, anything I try to change a property in the "MyViewController" Class nothing happens.
If anyone could please help me out, I would appreciate it.
Thank you
The problem is that the ColorSwatch is sending delegate messages to a dangling instance of MyViewController that it incorrectly allocated in it's initWithCoder: method.
UIControls shouldn't allocate ViewControllers to be their delegates... it goes the other way around.
Delete these lines...
// in ColorSwatch.m initWithCoder:
MyViewController *mvc = [[MyViewController alloc] initWithNibName:
#"MyViewController" bundle:nil];
self.colorSwatchDelegate = mvc;
Then, in MyViewController.m ...
- (void)viewDidLoad {
ColorSwatch *colorSwatchButton = [[ColorSwatch alloc] buttonWithType:UIButtonTypeCustom];
// or place a ColorSwatch in the xib, on MyViewController's view... But not before you
// you delete lines from initWithCoder, otherwise it's infinite circular allocation
colorSwatchButton.frame = CGRectMake(/* ... */);
colorSwatchButton addTarget:self action:#selector(csButtonPressed:) forControlEvent: UIControlEventTouchUpInside];
// and so on...
// now the important part:
colorSwatchButton.colorSwatchDelegate = self;
// see - the ViewController is in charge of allocation, sets itself up as the delegate
[self.view addSubview:colorSwatchButton];
}
Instead of building the button in code, you can use IB.
Step 1: make the delegate an outlet...
#property (nonatomic, retain) IBOutlet id <ColorSwatchDelegate> colorSwatchDelegate;
Step 2: draw the buttons in IB, and set their class to ColorSwatch.
Then you can skip the code I wrote in viewDidLoad.
Step 3: The newly placed button should now present an outlet in IB. You can drag from that to the MyViewController as you normally do.
There might be a connection problem in your IBOutlet photoLabelTextField, you may have forgotten to connect xib text field with your photoLabelTextField

How to add a popup UIView (of a customized class) on a UIViewController

I'm new on this, and I would like to get some advice because I don't know what I'm doing wrong.
I want to make an app in xcode, with a UIView with some items, and when you do something, another UIView (smaller than the first) pops up above the first UIView. The popup UIView would be a customized class.
I have started with the UIViewController template and the initial UIView, and I have linked all the items in the .storyboard, and it works. But when I create my own UIView class (from objective-C class), put the second UIView over the first in the storyboard and link it to my class, something goes wrong.
The UIView appears, but when I try to set it to hidden, it doesn't answer. It's like it's not receiving the messages, so I think I don't link it well programmatically and just appears because of the storyboard.
I don't know if I have to create another UIViewController instead of the UIView, or if this is the correct path.
Can anybody explain me a little, or just write a little code snippet with the instantiation of the second view and adding it?
Lots of thanks!!
(I paste some code, of the declaration in .h and instantiation in .m)
#import <UIKit/UIKit.h>
#import "EditView.h"
#interface ReleaseViewController : UIViewController <UIWebViewDelegate, UISearchBarDelegate> {
IBOutlet UIWebView *web;
IBOutlet UISearchBar *search;
IBOutlet EditView *evHack;
}
#property (nonatomic, retain) IBOutlet UIWebView *web;
#property (nonatomic, retain) IBOutlet UISearchBar *search;
#property (nonatomic, retain) IBOutlet EditView *evHack;
#end
- (void)viewDidLoad
{
[super viewDidLoad];
search.delegate = self;
web.delegate = self;
evHack = [evHack initWithFrame:CGRectMake(0, 44, 320, 377)];
[evHack setHidden:YES];
}
EditView Class (I still have nothing):
#import <UIKit/UIKit.h>
#interface EditView : UIView
#end
#import "EditView.h"
#implementation EditView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
NSLog(#"View created");
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
#end
initWithFrame only works when you alloc/init an app. If its already initialized, in this case by the storyboard, just set its frame:
evHack.frame = CGRectMake(0,44, 320, 377);
I don't know what it looks like in IB, But setting its frame in code may be redundant if you set it in IB too. To check whether evHack is hooked up right, NSLog evHack in viewDidLoad. If you get nil back, it's not hooked up right.

resize the Hosting View through addSubview in Core-Plot in XCode 4

I'm running into a wall trying to resize the Hosting View. The problem is I either get a full-screen plot or a blank screen. I'm hoping to get some leads to fix this problem:
I'm using Xcode 4 | IOS 4.3 | Recently downloaded core plot using hg:
I have two xib files (MainWindow & my ViewController)
My ViewController.xib file contains two objects: a View and Hosting View both at the same level:
+-View
+-Graph Hosting View
I get no erros in my code, but all I get a blank screen. I've searched for 3 days how to get around this problem, but haven't found something that works.
My xAppDelegate.h
#import <UIKit/UIKit.h>
#class CorePlotTestViewController;
#interface CorePlotTestAppDelegate : NSObject <UIApplicationDelegate> {
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet CorePlotTestViewController *viewController;
#end
My ViewController.h
#import <UIKit/UIKit.h>
#import "CorePlot-CocoaTouch.h"
#interface CorePlotTestViewController : UIViewController <CPTPlotDataSource>
{
CPTXYGraph *graph;
NSMutableArray *dataForPlot;
CPTGraphHostingView *graphView;
}
#property(readwrite, retain, nonatomic) NSMutableArray *dataForPlot;
#property(nonatomic, retain)IBOutlet CPTGraphHostingView* graphView;
My ViewController.m
#import "CorePlotTestViewController.h"
#interface CorePlotTestViewController(private)
- (void) configureTableHeader;
#end
#implementation CorePlotTestViewController
#synthesize dataForPlot;
#synthesize graphView;
-(void)dealloc
{
[dataForPlot release];
[super dealloc];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self configureTableHeader];
}
- (void) configureTableHeader
{
// here I implement the contents of the Hosting View
graph = [[CPTXYGraph alloc] initWithFrame: CGRectZero];
CPTGraphHostingView *hostingView = [(CPTGraphHostingView *)[CPTGraphHostingView alloc]
initWithFrame:CGRectZero];
[self.view addSubview:hostingView];
...
// etc
...
}
In your code, you initialize the hosting view using a CGRectZero frame, which is basically a frame with an origin at (0,0) and both a width and a height of 0 px. It is the reason why you don't see the graph at all when you run your project.
If you gave a custom size and location to the hosting view in Interface Builder, it is overridden by this code.
By the way, I'm not sure why you want to add the hosting view to the controller's view in the code. You just need to layout both components using Interface Builder, giving the hosting view the size and the location you want it to have.
Last thing : why do you add a 'T' to Core-Plot class names ? CPTPlotDataSource should simply be CPPlotDataSource; CPTXYGraph: CPXYGraph; etc.