Rahul
Rahul

Reputation: 509

why drawRect method is not being called?

#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

Upvotes: 0

Views: 1861

Answers (3)

Rahul
Rahul

Reputation: 509

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.

Upvotes: 0

Meltemi
Meltemi

Reputation: 38359

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

Upvotes: 5

Paul Lynch
Paul Lynch

Reputation: 19789

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

Upvotes: 3

Related Questions