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

View Single Post
Old 03-24-2009, 03:19 AM   #1 (permalink)
xworker
Registered Member
 
Join Date: Mar 2009
Posts: 27
xworker is on a distinguished road
Default drawRect not called

Hi all

Very new to iphone developement, but have 10yrs as a java developer.
I have two questions about a project of mine.

First:

Trying to draw some lines on the screen.

I have a view controller in which I try to trigger the drawRect method like this:

Code:
- (void)loadView {
	NSLog(@"chartView loading");
	chartView = [[ChartView alloc] initWithFrame:CGRectMake(1.0, 0.0, 1.0, 1.0)];
	[chartView setNeedsDisplay];
the view looks like this:
Code:
#import "ChartView.h"

#import <UIKit/UIKit.h>


@implementation ChartView


- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        // Initialization code
		NSLog(@"in init");
		
		
		    }
    return self;
}

-(void)drawRect:(CGRect)
 {
	NSLog(@"in drawRect");
    // Drawing code
	// CGContextRef context = UIGraphicsGetCurrentContext();
	 CGRect box = CGRectMake(40, 40, 240, 120);
	 CGContextSetRGBFillColor(context, 1.0,1.0,1.0,1.0);
	 CGContextFillRect(context, box);
	 
	 CGContextSetRGBStrokeColor(context, 0.0, 1.0, 0.0, 1.0);
	 CGContextStrokeRectWithWidth(context, box, 10);
	 
	
}


- (void)dealloc {
    [super dealloc];
}


@end
I see printouts of the "initWithFrame" methode being called but not the drawRect. Shouldn't drawRect be triggerd for the setNeedsDispaly call?


Question nr 2.

How do i get my view "chartView" into the IB? I read that you are supposed to be able to drag it into the window with "File Owner" and that stuff, and then it should be available. I see the green + sign when I drag it there but it doesnt show up anywhere i the library window. I want to make that view smaller and fit in on the view togheter with a few textinputs and buttons.


Thanks for your time.

/x

Last edited by xworker; 03-24-2009 at 05:54 AM.
xworker is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,630
Threads: 94,089
Posts: 402,801
Top Poster: BrianSlick (7,990)
Welcome to our newest member, RickyGervaiss
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:00 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.