Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Tools & Utilities

Reply
 
LinkBack Thread Tools Display Modes
Old 01-12-2011, 07:47 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 4
matto.g1456 is on a distinguished road
Default Draw a line Graph with Quartz

I am so close to the end but am really stuck, any help would be great.
So basically I am trying to draw a line graph on a UIView which is on a UIScrollview. The draw rect method is in the UIView Subclass and everything is working there, I have gridlines and labels on the axis and I can draw manually onto it. But the problem I have is that I cannot read the NSMutableArray of the CGPoints, which are the x and y coords.
The ViewController performs a calculation and the results are written to the NSMutable array and this is all working fine as well, I can see the CGpoints and their values being written with NSLogs in the ViewController.
I have tried various ways to set the NSMutableArray up as a global but to no avail, everything runs but while I can see the points being written in the ViewController they are just not visible to the UIView Subclass.
I have also tried to use the addObserver and observeValueForKeyPath methods and once again while everything runs the subclass cannot see the array.
Any ideas, suggestions, tips or thoughts would be great
matto.g1456 is offline   Reply With Quote
Old 01-12-2011, 09:20 AM   #2 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 4
matto.g1456 is on a distinguished road
Default

I am so close to the end but am really stuck, any help would be great.
So basically I am trying to draw a line graph on a UIView which is on a UIScrollview. The draw rect method is in the UIView Subclass and everything is working there, I have gridlines and labels on the axis and I can draw manually onto it. But the problem I have is that I cannot read the NSMutableArray of the CGPoints, which are the x and y coords.
The ViewController performs a calculation and the results are written to the NSMutable array and this is all working fine as well, I can see the CGpoints and their values being written with NSLogs in the ViewController.
I have tried various ways to set the NSMutableArray up as a global but to no avail, everything runs but while I can see the points being written in the ViewController they are just not visible to the UIView Subclass.
I have also tried to use the addObserver and observeValueForKeyPath methods and once again while everything runs the subclass cannot see the array.
Any ideas, suggestions, tips or thoughts would be great

This is the code in the ViewController responsible for generating the NSMutableArray and posting a notification that the array has changed
Code:
-(IBAction)calculate:(id)sender {

        float xaxis=10
        float d=20

	NSString *const key = @"points";
	[self willChangeValueForKey:key];
	
	CGPoint pt = CGPointMake(xaxis, d);
	[self.points addObject:[NSValue valueWithCGPoint:pt]];

	[self didChangeValueForKey:key];
	
	NSLog(@"fromviewpts%@", NSStringFromCGPoint(pt));
	NSLog(@"fromviewnum%@", [NSString stringWithFormat:@"%d points", self.points.count ]);
	
	}
and this is the code in the UIViewSubclass that is supposed to listen for changes to the array
Code:
- (void) ArrayChanged {
    [points addObserver:self forKeyPath:@"points" options:0 context:NULL];
    //[[points mutableArrayValueForKey:@"theArray"] addObject:[NSString string]];
}


- (void) observeValueForKeyPath: (NSString* ) keyPath ofObject: (id) object
			   change: (NSDictionary*) change context: (void*) context 
{
    NSAssert([keyPath isEqualToString:@"points"], @"Has Changed.");
    NSLog(@"from assert%@", [NSString stringWithFormat:@"%d points", points.count ]);

}
matto.g1456 is offline   Reply With Quote
Old 01-13-2011, 05:04 AM   #3 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 4
matto.g1456 is on a distinguished road
Default Working Nicely

Got it all working and learnt a lot along the way, basically I ended up using a singleton class to handle the NSMutableArray so that the ViewController could write data to it and the UIView subclass which handled the drawing could read the data from it.
matto.g1456 is offline   Reply With Quote
Reply

Bookmarks

Tags
nsmutable array data, subclass

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 404
11 members and 393 guests
AppleDev, chemistry, Emy, Gi-lo, ipodphone, mistergreen2011, pipposanta, QuantumDoja, Retouchable, SLIC
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,129
Posts: 402,924
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:24 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0