I am new in iOS and I am facing problem regarding to do validation of view. I have created Signature like view How to draw Signature on UIView, and now I want to do validation by using this code
-(IBAction)SavebtnClick:(id)sender
{
if(drawSignView==nil)
{
UIAlertView *alertviewshow =[[UIAlertView alloc] initWithTitle:@"Warning!" message:@"Pease Sign" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alertviewshow show];
}
else if (drawSignViewClient==nil)
{
UIAlertView *alertviewshow =[[UIAlertView alloc] initWithTitle:@"Warning!" message:@"Please Sign" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alertviewshow show];
}
else
{
viewcontroller1 *management =[[viewcontroller1 alloc] initWithNibName:@"viewcontroller1" bundle:nil];
[self.navigationController pushViewController:management animated:YES];
}
}
But I am not getting success. Please tell me what I am doing wrong.
I want to do validation.
if I have not sign it shows the message.
Please give me suggestion.
Thanks in advance!
I save Image and used condition
UIGraphicsBeginImageContext(self.drawSignView.bounds.size);
[[self.drawSignView.layer presentationLayer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// NSData *postData = UIImageJPEGRepresentation(viewImage, 1.0);
// Store the data
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSData *imageData = UIImageJPEGRepresentation(viewImage, 100);
[defaults setObject:imageData forKey:@"image"];
[defaults synchronize];
if(viewImage==nil)
{
UIAlertView *alertviewshow =[[UIAlertView alloc] initWithTitle:@"Warning!" message:@"Pease Sign" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alertviewshow setTag:1];
[alertviewshow show];
}
But it not work because it contain blank image.
Try this code its definatly work.
Please check this answer
For that my suggestion is to check
UIImage
rather thenUIView
, That means are you getting the signature image or not. Then you should check likeAnd for another signature
And if you getting not nil image without sign it then use SinatureView which will give you nil image if you did't sign it then you can validate it.
If you check the
UIView
(i.e. Your signature view) is nil or not,You will get always not nil view because you have initialized it.