drawRect is not being called
I need to draw an image in a rectangle so for that am using drawRect method.i observed that it is not being called.The output i can see only the blank screen.Am using MAC OS and i need to test the App in Iphone OS 3+.Please can anyone solve my problem.Here is my code:
-(IBAction)calling
{
int a=0;
a=a+1;
[self.view setNeedsDisplay]; //InRect:CGRectMake(78, 43, 200, 138)];
}
- (void)drawRect:(CGRect)rect {
UIImage *myImage = [UIImage imageNamed:@"btbp.jpg"];
CGRect imageRect = CGRe开发者_运维百科ctMake(10, 10, 300, 400);
[myImage drawInRect:imageRect];
[self.view setNeedsDisplay];
[myImage release];
}
i donno where i was wrong:(
Is your
drawRect
method on an actual view? Or is it on the view controller, which is what it seems like?drawRect
is something you write/override on the view itself.You should not call
release
on themyImage
object, since you didn'talloc
it yourself.
If this isn't making 100% sense, I'd recommend you start with the iOS Cocoa Views documentation to understand how this all fits together.
精彩评论