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