开发者

drawRect is not being called

开发者 https://www.devze.com 2023-01-23 05:18 出处:网络
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

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:(


  1. 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.

  2. You should not call release on the myImage object, since you didn't alloc 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消