views:

284

answers:

3
#import <UIKit/UIKit.h>

@interface quartzViewController : UIViewController {
 IBOutlet UIView *myView;

}

@end


#import "quartzViewController.h"

@implementation quartzViewController


   -(void)drawRect:(CGRect)rect
   {   

 CGContextRef  context = UIGraphicsGetCurrentContext();
 CGContextSelectFont(context, "Arial", 24, kCGEncodingFontSpecific);
 CGContextSetTextPosition(context,80,80);
 CGContextShowText(context, "hello", 6);
 //not even this works
 CGContextShowTextAtPoint(context, 1,1, "hello", 6);
   }

   - (void)viewDidLoad {
 [myView setNeedsDisplay];

 [super viewDidLoad];
   }

Will I have to make any changed in the nib?

Thanks

+1  A: 

drawRect: is a UIView method, not a UIViewController method.

Paul Lynch
+4  A: 

You've subclassed UIViewController which has no drawRect to override. drawRect is a method of UIView.

Meltemi
yeah thanx for the reply, i have got my answer, you are right, I took a new class which i inherit from UIVIEW and i found drawRect method ,which is not called...
If you got the answer then you should select them as accepted . you can read the FAQ .
hib
A: 

i have got my answer, I took a new class which i inherit from UIVIEW and i found drawRect method ,which is not called..

THE MISTAKE WAS, i was declaring the method in UIVIEWCONTRLLER CLASSS, rather i had to do it in a new class in herited from UIView.

FYI- Stack Overflow works a little different than most forums out there. the convention here is to mark the "correct" answer with a check mark rather than create a new "answer". that way future users can quickly see what worked for the original poster...and contributors get "reputation" points for helping out. And YOU should get a few points for selecting an answer and effectively "closing" this topic.
Meltemi