About updating a View using in iPhone using Objective C.

Posted by Tattat on Stack Overflow See other posts from Stack Overflow or by Tattat
Published on 2010-04-05T07:03:34Z Indexed on 2010/04/05 7:13 UTC
Read the original article Hit count: 352

I have a scene, called testScene, it works like this:

@interface testScene : myScene {
 IBOutlet UIView *subview;
 IBOutlet UIView *drawingCanvasView;
 IBOutlet UIButton *update;
}

- (void)updateDrawingCanvas: (id) sender;

and when the user click the button, update, it will run the updateDrawingCanvas method. So, I have a drawingCanvasView, which gave a drawingCanvas.h, and .m, it like this:

#import <UIKit/UIKit.h>


@interface DrawingCanvasView : UIView {
 CGImageRef image;

}

-(void)setNeedsDisplayInRect:(CGContextRef)context;

@end

In the DrawingCanvasView, I have a drawRect method like this:

 CGContextRef context = UIGraphicsGetCurrentContext();
 CGContextSetLineWidth(context, 2.0); 
 CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor); 
 CGContextMoveToPoint(context, 0.0f, 0.0f);
 CGContextAddLineToPoint(context, 100.0f, 100.0f); 
 CGContextStrokePath(context);

And I want the user click the button, and execute this, so I added a new method called setNeedsDisplayInRect:

 CGContextRef context = UIGraphicsGetCurrentContext();
 CGContextSetLineWidth(context, 2.0); 
 CGContextSetStrokeColorWithColor(context, [UIColor yellowColor].CGColor); 
 CGContextMoveToPoint(context, 0.0f, 0.0f);
 CGContextAddLineToPoint(context, 200.0f, 200.0f); 
 CGContextStrokePath(context);

But I can't called that in my updateDrawingCanvas method, it work like this:

- (void)updateDrawingCanvas: (id) sender{
 NSLog(@"loaded");
 [DrawingCanvasView setNeedsDisplayInRect:UIGraphicsGetCurrentContext()];
}

It my logic / concept right? or something I did wrong, thx.

© Stack Overflow or respective owner

Related posts about iphone-sdk-3.0

Related posts about core-graphics