0

I have a view on which I can draw. When the user clicks on cancel button, the view is cleared and new Image is drawn in that view. I am posting my code. Can anyone help?

#import "SignatureViewController.h"


@implementation SignatureViewController
@synthesize salesToolBar;



-(void)buttonpressed
{
    NSString *allElements = [myarray componentsJoinedByString:@""];
    NSLog(@"%@", allElements);}


-(void)buttonclear{

        [drawImage removeFromSuperview];

    //UIGraphicsBeginImageContext(CGSizeMake(self.view.frame.size.height, self.view.frame.size.width));       
     drawImage = [[UIImageView alloc] initWithImage:nil];
    [drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width )];
    drawImage.frame = self.view.frame;
   [self.view addSubview:drawImage];
    self.view.backgroundColor = [UIColor greenColor];
    mouseMoved = 0;
        //[super viewDidLoad];

}

-(void)buttoncancel{
    [[self navigationController] popViewControllerAnimated: YES];
     [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;

}


- (void)viewDidLoad {
    [super viewDidLoad];
    myarray = [[NSMutableArray alloc] init];


    CGFloat x = self.view.bounds.size.width / 2.0;
    CGFloat y = self.view.bounds.size.height / 2.0;
    CGPoint center = CGPointMake(y, x);

    // set the new center point
    self.view.center = center;

    CGAffineTransform transform = self.view.transform;
        transform = CGAffineTransformRotate(transform, -(M_PI / 2.0));

    self.view.transform = transform;

    self.view.backgroundColor = [UIColor greenColor];
    self.title = @"Signature";

    [self createToolbar];

    NSLog(@"View Did Load Run");


}

- (void)viewDidAppear:(BOOL)animated {
    NSLog(@"Self.view.frame.height = %f and width = %f ", self.view.frame.size.height, self.view.frame.size.width);
    NSLog(@"View Did Appear Run");
    self.navigationController.navigationBarHidden=TRUE;
    [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;



    [super viewDidLoad];

}
Luke
  • 7,110
  • 6
  • 45
  • 74
user771385
  • 11
  • 5
  • Can you be a bit more precise with what you need? How is this new image available? Right now it seems to `nil`. You are sending a `drawInRect:` message to it. This code has a few more errors. – Deepak Danduprolu Jun 06 '11 at 18:50

1 Answers1

0

Sounds like you need to call setNeedsDisplay: on the view. :)

Luke
  • 11,426
  • 43
  • 60
  • 69
  • Well the image is a image drawn on a view.My imageview is called drawimage.I am posting the whole code.I think I fixed all except the cancel button. – user771385 Jun 06 '11 at 18:53
  • Yep, so try calling the following on the view that contains the imageview... [self.view setNeedsDisplay]; – Luke Jun 06 '11 at 18:56
  • My view is not getting cleared properly,so after button clear when I try to redraw a image ,i get only a part of screen,the whole screen is avaialable on first time.So I need help in resizing my screen so that After button clear I get the full screen. – user771385 Jun 06 '11 at 19:00
  • So when you say you only get part of the screen - what do your NSLogs say for self.frame.size.height and width? Also, in buttonClear I can see where drawImage gets alloc'd - this should really be in viewDidLoad I think... assuming it should already exist, and the clear button doesn't keep creating and removing it every time it is pressed? – Luke Jun 06 '11 at 19:10
  • yes its true...i am kind of puzzled how to clear my view and redraw it..I am new in xcode – user771385 Jun 06 '11 at 19:12
  • h=416 w 320 in first case h =460 w=320 2nd time – user771385 Jun 06 '11 at 19:19
  • I think this will help you to sort out how to change your image in the image view: http://stackoverflow.com/questions/706240/how-can-i-change-the-image-displayed-in-an-uiimageview-programmatically I'm not sure why your view controller changes size on the second time... you could just hardcode the values for now and then try to work back to figure it out, or post more code. – Luke Jun 06 '11 at 21:33