Friday, 15 March 2013

disable ARC for a single file in a project IOS


It is possible to disable ARC for individual files by adding the -fno-objc-arc compiler flag for those files.
You add compiler flags in Targets -> Build Phases -> Compile Sources. You have to double click on the right column of the row under Compiler Flags. You can also add it to multiple files by holding the cmd button to select the files and then pressing enter to bring up the flag edit box.

Reference- http://stackoverflow.com/questions/6646052/how-can-i-disable-arc-for-a-single-file-in-a-project

How to Convert UIView to PDF within iOS?




-(IBAction)mailaspdf{
    
    [self createPDFfromUIView:self.view saveToDocumentsWithFileName:@"myPdf.pdf"];
}


-(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
    // Creates a mutable data object for updating with binary data, like a byte array
    NSMutableData *pdfData = [NSMutableData data];

    // Points the pdf converter to the mutable data object and to the UIView to be converted
    UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
    UIGraphicsBeginPDFPage();
    CGContextRef pdfContext = UIGraphicsGetCurrentContext();


    // draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData

    [aView.layer renderInContext:pdfContext];

    // remove PDF rendering context
    UIGraphicsEndPDFContext();

    // Retrieves the document directories from the iOS device
    NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);

    NSString* documentDirectory = [documentDirectories objectAtIndex:0];
    NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];

    // instructs the mutable data object to write its context to a file on disk
    [pdfData writeToFile:documentDirectoryFilename atomically:YES];
    NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
}
Reference- http://stackoverflow.com/questions/5443166/how-to-convert-uiview-to-pdf-within-ios

Wednesday, 6 March 2013

Tap and Swipe Gesture iPhone

Single tap Gesture. 

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget: self action:@selector(doSingleTap)];
    singleTap.numberOfTapsRequired = 1;
    [self.view addGestureRecognizer:singleTap];


- (void)doSingleTap{

}

Swipe Left Gesture and Swipe Right

 UISwipeGestureRecognizer *swipeLeftGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeftGesture:)];
    swipeLeftGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
    [self.view addGestureRecognizer:swipeLeftGestureRecognizer];
    // [swipeLeftGestureRecognizer release];
    
    UISwipeGestureRecognizer *swipeRightGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightGesture:)];
    [self.view addGestureRecognizer:swipeRightGestureRecognizer];


- (void)swipeLeftGesture:(UISwipeGestureRecognizer *)sender{
}

- (void)swipeRightGesture:(UISwipeGestureRecognizer *)sender{
   
    //[self.navigationController popViewControllerAnimated:YES];
}

Tuesday, 5 March 2013

Horizontal scrolling buttons in iPhone


   IBOutlet UIScrollView *scrollView1;
    UIButton *button;

const CGFloat kScrollObjHeight = 110;
const CGFloat kScrollObjWidth = 110.0;
const NSUInteger kNumImages = 7;



- (void)viewDidLoad
{
[scrollView1 setBackgroundColor:[UIColor blackColor]];
[scrollView1 setCanCancelContentTouches:NO];
scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView1.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview
scrollView1.scrollEnabled = YES;
// pagingEnabled property default is NO, if set the scroller will stop or snap at each photo
// if you want free-flowing scroll, don't set this property.
scrollView1.pagingEnabled = YES;
// load all the images from our bundle and add them to the scroll view
NSUInteger i;
for (i = 0; i <= kNumImages; i++)
{
NSString *imageName = [NSString stringWithFormat:@"pt%d.png", i];
UIImage *image = [UIImage imageNamed:imageName];
//UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        
        
// setup each frame to a default height and width, it will be properly placed when we call "updateScrollList"
        
        button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button addTarget:self
                   action:@selector(aMethod:)
         forControlEvents:UIControlEventTouchDown];
        // [button setTitle:@"Show View" forState:UIControlStateNormal];
        [button setImage:image forState:UIControlStateNormal];
        //button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
        // [view addSubview:button];
        
        
CGRect rect = button.frame;
rect.size.height = kScrollObjHeight;
rect.size.width = kScrollObjWidth;
button.frame = rect;
        button.tag=i;
//imageView.tag = i; // tag our images for later use when we place them in serial fashion
[scrollView1 addSubview:button];
//[imageView release];
}
[self layoutScrollImages];
    
    
}



- (void)layoutScrollImages
{
UIButton *view = nil;
NSArray *subviews = [scrollView1 subviews];
    
// reposition all image subviews in a horizontal serial fashion
CGFloat curXLoc =0;
for (view in subviews)
{
if ([view isKindOfClass:[UIButton class]] && view.tag > 0)
{
CGRect frame = view.frame;
frame.origin = CGPointMake(curXLoc, 0);
view.frame = frame;
curXLoc += (kScrollObjWidth);
}
}
// set the content size so it can be scrollable
[scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [scrollView1 bounds].size.height)];
}




-(void)aMethod:(id)sender{
    
    
    UIButton *but=(UIButton *)sender;
    NSLog(@"Hee %d",but.tag);
    if(but.tag==1){
        
   

        }else if(but.tag==2){
        pp1ViewController * viewController = [[pp1ViewController alloc] initWithNibName:@"pp1ViewController" bundle:nil];
[self.navigationController pushViewController:viewController animated:NO];
        
       
    }else if(but.tag==3){
       }    
}


Tuesday, 12 February 2013

ID Profile Source Code- DetailView Controller


//.h



#import <UIKit/UIKit.h>
@interface DetailViewController : UIViewController{
    
    IBOutlet UITableView *myTable;
    NSMutableArray *categoryArray;
    
    NSMutableArray *imageArray;
    NSMutableArray *nameArray;
    NSMutableArray *distrctArray;
    NSMutableArray *emailArray;
    NSMutableArray *mobileArray;
    
    
        
    NSUserDefaults *currentDefaults;
    
    NSData *ImageData1;
    
    int q;
}


@end

//.m

#import "DetailViewController.h"
#import "TableViewCell.h"



@implementation DetailViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    currentDefaults = [NSUserDefaults standardUserDefaults];
    
    NSData *dataRepresentingSavedArray = [currentDefaults objectForKey:@"savedName"];
    NSMutableArray *oldSavedArray = [NSKeyedUnarchiver unarchiveObjectWithData:dataRepresentingSavedArray];
    nameArray = [[NSMutableArray alloc] initWithArray:oldSavedArray];
    NSLog(@"name-- %d",[nameArray count]);
    
    NSData *dataRepresentingSavedArray0 = [currentDefaults objectForKey:@"savedImage"];
    NSMutableArray *oldSavedArray0 = [NSKeyedUnarchiver unarchiveObjectWithData:dataRepresentingSavedArray0];
    imageArray = [[NSMutableArray alloc] initWithArray:oldSavedArray0];
    NSLog(@"image-- %d",[imageArray count]);
    
    NSData *dataRepresentingSavedArray1 = [currentDefaults objectForKey:@"savedDt"];
    NSMutableArray *oldSavedArray1 = [NSKeyedUnarchiver unarchiveObjectWithData:dataRepresentingSavedArray1];
    distrctArray = [[NSMutableArray alloc] initWithArray:oldSavedArray1];
    NSLog(@"distrct-- %d",[distrctArray count]);
    
    NSData *dataRepresentingSavedArray2 = [currentDefaults objectForKey:@"savedEmail"];
    NSMutableArray *oldSavedArray2 = [NSKeyedUnarchiver unarchiveObjectWithData:dataRepresentingSavedArray2];
    emailArray = [[NSMutableArray alloc] initWithArray:oldSavedArray2];
    NSLog(@"email-- %d",[emailArray count]);
    
    NSData *dataRepresentingSavedArray3 = [currentDefaults objectForKey:@"savedMobile"];
    NSMutableArray *oldSavedArray3 = [NSKeyedUnarchiver unarchiveObjectWithData:dataRepresentingSavedArray3];
    mobileArray = [[NSMutableArray alloc] initWithArray:oldSavedArray3];
    NSLog(@"mobile-- %d",[mobileArray count]);
    
  
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    //   [self.navigationController.navigationBar setAlpha:1.0];
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [nameArray count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 85;
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     
    static NSString *cellID= @"TableViewCell";
    TableViewCell *cell = (TableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellID];
    
    if(cell==nil)
    {
        
        
        NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:nil options:nil];
        
        for(id currentObject in nibObjects)
        {
            if([currentObject isKindOfClass: [TableViewCell class]])
            {
                cell = (TableViewCell *)currentObject;
            }
            
        }
    }
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(250, 50, 49, 19);
    //[button setBackgroundColor:[UIColor clearColor]];
    UIImage *buttonImage = [UIImage imageNamed:@"DoneN.png"];
    [button setBackgroundImage:buttonImage forState:UIControlStateNormal];
    
    [button addTarget:self action:@selector(del:)forControlEvents:UIControlEventTouchUpInside];
    button.tag = indexPath.row;
    [cell.contentView addSubview:button];
    
    
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    button1.frame = CGRectMake(250, 15, 50, 20);
    [button1 setBackgroundColor:[UIColor clearColor]];
    
    UIImage *buttonImage1 = [UIImage imageNamed:@"edit.png"];
    [button1 setBackgroundImage:buttonImage1 forState:UIControlStateNormal];
    
    
    [button1 addTarget:self action:@selector(edit:)forControlEvents:UIControlEventTouchUpInside];
    button1.tag = indexPath.row;
    [cell.contentView addSubview:button1];
    
    // Configure the cell.
    cell.title1.text=[nameArray objectAtIndex:indexPath.row];
    cell.subTitle1.text=[distrctArray objectAtIndex:indexPath.row];
    NSData *imgData = (NSData*)[imageArray objectAtIndex:indexPath.row];
    UIImage* imge = [[UIImage alloc] initWithData:imgData];
    cell.img1.image=imge;
        
    return cell;
}
-(void)del:(id)sender
{

    UIButton *tappedButton = (UIButton*)sender;
    q=tappedButton.tag;
    
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Are you sure to delete this Profile?" message:nil delegate:self cancelButtonTitle:@"ok" otherButtonTitles:@"Don't Allow", nil];
    [alert show];
  
    
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
    
if (buttonIndex == 0) {
      
        NSLog(@"Tag--%d",q);
        
        [nameArray removeObjectAtIndex:q];
        [imageArray removeObjectAtIndex:q];
        [distrctArray removeObjectAtIndex:q];
        [emailArray removeObjectAtIndex:q];
        [mobileArray removeObjectAtIndex:q];
    
        [[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:imageArray] forKey:@"savedImage"];
        [[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:nameArray] forKey:@"savedName"];
        [[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:distrctArray] forKey:@"savedDt"];
        [[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:emailArray] forKey:@"savedEmail"];
        [[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:mobileArray] forKey:@"savedMobile"];

        [[NSUserDefaults standardUserDefaults] synchronize];
    
        [myTable reloadData];
        [self.view setNeedsDisplay];
    }
if (buttonIndex == 1) {
        NSLog(@"button");
    }
    
    
}
-(void)edit:(id)sender{
    
    UIButton *tappedButton = (UIButton*)sender;
    q=tappedButton.tag;
    NSString *index=[NSString stringWithFormat:@"%d",q];
    [currentDefaults setObject:index forKey:@"edit"];
    [self.navigationController popViewControllerAnimated:YES];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

ID Profile Source Code- MasterViewController


//.h
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>

@interface MasterViewController : UIViewController<UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIPrintInteractionControllerDelegate>{
    

    
    IBOutlet UITextField *nameField;
    IBOutlet UITextField *districtField,*emailField,*mobileField;
    
   IBOutlet UIImageView * imageView;
    NSMutableArray *imageArray;
    NSMutableArray *nameArray;
    NSMutableArray *distrctArray;
    NSMutableArray *emailArray;
    NSMutableArray *mobileArray;
    
    
    NSUserDefaults *currentDefaults;
    int p;
}



-(IBAction)photoButton:(id)sender;
-(IBAction)SaveButton:(id)sender;
-(IBAction)list:(id)sender;

@end

//.m

CGFloat animatedDistance;
static const CGFloat KEYBOARD_ANIMATION_DURATION = 0.3;
static const CGFloat MINIMUM_SCROLL_FRACTION = 0.2;
static const CGFloat MAXIMUM_SCROLL_FRACTION = 0.8;
static const CGFloat PORTRAIT_KEYBOARD_HEIGHT = 216;
static const CGFloat LANDSCAPE_KEYBOARD_HEIGHT = 162;

#import "MasterViewController.h"

#import "DetailViewController.h"

#import "Base64.h"


@implementation MasterViewController
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    // signup.enabled=NO;
    CGRect textFieldRect =
    [self.view.window convertRect:textField.bounds fromView:textField];
    CGRect viewRect =
    [self.view.window convertRect:self.view.bounds fromView:self.view];
    
    
    CGFloat midline = textFieldRect.origin.y + 0.5 * textFieldRect.size.height;
    CGFloat numerator =
    midline - viewRect.origin.y
    - MINIMUM_SCROLL_FRACTION * viewRect.size.height;
    CGFloat denominator =
    (MAXIMUM_SCROLL_FRACTION - MINIMUM_SCROLL_FRACTION)
    * viewRect.size.height;
    CGFloat heightFraction = numerator / denominator;
    
    if (heightFraction < 0.0)
    {
        heightFraction = 0.0;
    }
    else if (heightFraction > 1.0)
    {
        heightFraction = 1.0;
    }
    
    UIInterfaceOrientation orientation =
    [[UIApplication sharedApplication] statusBarOrientation];
    if (orientation == UIInterfaceOrientationPortrait ||
        orientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        animatedDistance = floor(PORTRAIT_KEYBOARD_HEIGHT * heightFraction);
    }
    else
    {
        animatedDistance = floor(LANDSCAPE_KEYBOARD_HEIGHT * heightFraction);
    }
    
    CGRect viewFrame = self.view.frame;
    viewFrame.origin.y -= animatedDistance;
    
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
    
    [self.view setFrame:viewFrame];
    
    [UIView commitAnimations];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    CGRect viewFrame = self.view.frame;
    viewFrame.origin.y += animatedDistance;
    
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
    
    [self.view setFrame:viewFrame];
    
    [UIView commitAnimations];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if(textField == nameField) {
[districtField becomeFirstResponder];
}
else if(textField == districtField) {
[emailField becomeFirstResponder];
}
    else if(textField == emailField) {
[mobileField becomeFirstResponder];
}
    else if(textField == mobileField) {
[mobileField resignFirstResponder];
}
return YES;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    currentDefaults = [NSUserDefaults standardUserDefaults];
       
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    NSData *dataRepresentingSavedArray0 = [currentDefaults objectForKey:@"savedImage"];
    NSMutableArray *oldSavedArray0 = [NSKeyedUnarchiver unarchiveObjectWithData:dataRepresentingSavedArray0];
    imageArray = [[NSMutableArray alloc] initWithArray:oldSavedArray0];
    NSLog(@"image-- %d",[imageArray count]);
    
    
    NSData *dataRepresentingSavedArray = [currentDefaults objectForKey:@"savedName"];
    NSMutableArray *oldSavedArray = [NSKeyedUnarchiver unarchiveObjectWithData:dataRepresentingSavedArray];
    nameArray = [[NSMutableArray alloc] initWithArray:oldSavedArray];
    NSLog(@"name-- %d",[nameArray count]);
    
    NSData *dataRepresentingSavedArray1 = [currentDefaults objectForKey:@"savedDt"];
    NSMutableArray *oldSavedArray1 = [NSKeyedUnarchiver unarchiveObjectWithData:dataRepresentingSavedArray1];
    distrctArray = [[NSMutableArray alloc] initWithArray:oldSavedArray1];
    NSLog(@"distrct-- %d",[distrctArray count]);
    
    NSData *dataRepresentingSavedArray2 = [currentDefaults objectForKey:@"savedEmail"];
    NSMutableArray *oldSavedArray2 = [NSKeyedUnarchiver unarchiveObjectWithData:dataRepresentingSavedArray2];
    emailArray = [[NSMutableArray alloc] initWithArray:oldSavedArray2];
    NSLog(@"email-- %d",[emailArray count]);
    
    NSData *dataRepresentingSavedArray3 = [currentDefaults objectForKey:@"savedMobile"];
    NSMutableArray *oldSavedArray3 = [NSKeyedUnarchiver unarchiveObjectWithData:dataRepresentingSavedArray3];
    mobileArray = [[NSMutableArray alloc] initWithArray:oldSavedArray3];
    NSLog(@"mobile-- %d",[mobileArray count]);
    
    if([currentDefaults objectForKey:@"edit"]){
    NSString *index=[currentDefaults valueForKey:@"edit"];
     p=[index intValue];
    NSLog(@"Hi- %d",p);
        NSData *imgData = (NSData*)[imageArray objectAtIndex:p];
        UIImage* imge = [[UIImage alloc] initWithData:imgData];
        imageView.image=imge;
        nameField.text=[nameArray objectAtIndex:p];
        districtField.text=[distrctArray objectAtIndex:p];
        emailField.text=[emailArray objectAtIndex:p];
        mobileField.text=[mobileArray objectAtIndex:p];
    }
    
}
-(IBAction)photoButton:(id)sender{
    
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Use photo from:"
                                                             delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Camera",@"Library",nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
    [actionSheet showInView:self.view ];
    
}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if (buttonIndex == 0) {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
          [self presentViewController:picker animated:YES completion:nil];
        
} else if (buttonIndex == 1) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
          [self presentViewController:picker animated:YES completion:nil];
    }
  
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion:nil];
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    
}

-(IBAction)SaveButton:(id)sender{
    [mobileField resignFirstResponder];
    
    NSString *msgStr = @"";
BOOL bErr = NO;
    NSString *emailRegEx = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegEx];
    
    if(imageView.image==[UIImage imageNamed:@"noimage.jpeg"]) {
msgStr = @"Choose an Image";
bErr = YES;
    }
    else if(nameField.text.length == 0) {
msgStr = @"Please provide your name";
bErr = YES;
[nameField becomeFirstResponder];
}
else if(districtField.text.length == 0) {
msgStr = @"Please provide your District";
bErr = YES;
[districtField becomeFirstResponder];
}else if(emailField.text.length == 0) {
msgStr = @"Please provide your email";
bErr = YES;
[emailField becomeFirstResponder];
}
    
    
    else if ([emailTest evaluateWithObject:emailField.text] == NO)
    {
        
        msgStr = @"Invalid Email Id! Please try again";
bErr = YES;
[emailField becomeFirstResponder];
    }
    
    
if(bErr) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:msgStr delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
//[alert release];
return;
}
    
    NSData *ImageData1 = UIImageJPEGRepresentation(imageView.image, 0.9);
    
     if([currentDefaults objectForKey:@"edit"]){
        NSLog(@"Hiqqq- %d",p);
         [imageArray replaceObjectAtIndex:p withObject:ImageData1];
         [nameArray replaceObjectAtIndex:p withObject:nameField.text];
         [distrctArray replaceObjectAtIndex:p withObject:districtField.text];
         [emailArray replaceObjectAtIndex:p withObject:emailField.text];
         [mobileArray replaceObjectAtIndex:p withObject:mobileField.text];
    }else{
    
    [imageArray addObject:ImageData1];
    [nameArray addObject:nameField.text];
    [distrctArray addObject:districtField.text];
    [emailArray addObject:emailField.text];
    [mobileArray addObject:mobileField.text];
    }
    
    [currentDefaults setObject:[NSKeyedArchiver archivedDataWithRootObject:imageArray] forKey:@"savedImage"];
    [currentDefaults setObject:[NSKeyedArchiver archivedDataWithRootObject:nameArray] forKey:@"savedName"];
    [currentDefaults setObject:[NSKeyedArchiver archivedDataWithRootObject:distrctArray] forKey:@"savedDt"];
    [currentDefaults setObject:[NSKeyedArchiver archivedDataWithRootObject:emailArray] forKey:@"savedEmail"];
    [currentDefaults setObject:[NSKeyedArchiver archivedDataWithRootObject:mobileArray] forKey:@"savedMobile"];
     //[[NSUserDefaults standardUserDefaults] synchronize];
    [self print];
    
    imageView.image=[UIImage imageNamed:@"noimage.jpeg"];
    nameField.text=@"";
    districtField.text=@"";
    emailField.text=@"";
    mobileField.text=@"";
  
}

-(void)print{
    
        
   
    if (![UIPrintInteractionController isPrintingAvailable]) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Printer Availability Error Title", @"")
                                                             message:NSLocalizedString(@"Printer Availability Error Message", @"")
                                                            delegate:nil
                                                   cancelButtonTitle:NSLocalizedString(@"OK", @"OK")
                                                   otherButtonTitles:nil];
        [alertView show];
        return;
    }
    
    UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
    
    if(!pic) {
        NSLog(@"Couldn't get shared UIPrintInteractionController!");
        return;
    }
    
    pic.delegate = self;
    
    UIPrintInfo *printInfo = [UIPrintInfo printInfo];
    printInfo.outputType = UIPrintInfoOutputGeneral;
    printInfo.jobName = @"Sample";
    pic.printInfo = printInfo;
    
    NSString *htmlString = [self prepareHTMLText];
    UIMarkupTextPrintFormatter *htmlFormatter = [[UIMarkupTextPrintFormatter alloc] initWithMarkupText:htmlString];
    htmlFormatter.startPage = 0;
    htmlFormatter.contentInsets = UIEdgeInsetsMake(72.0, 72.0, 72.0, 72.0); // 1-inch margins on all sides
    htmlFormatter.maximumContentWidth = 6 * 72.0;   // printed content should be 6-inches wide within those margins
    pic.printFormatter = htmlFormatter;
    
    pic.showsPageRange = YES;
    
    void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
    ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
        
        if (!completed && error) {
            NSLog(@"Printing could not complete because of error: %@", error);
        }
    };
    
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        // [pic presentFromBarButtonItem:self.myPrintBarButton animated:YES completionHandler:completionHandler];
        
    } else {
        [pic presentAnimated:YES completionHandler:completionHandler];
    }

    
}
    
    
- (NSString *)prepareHTMLText {
   
    NSMutableString *body = [NSMutableString stringWithString:@"<!DOCTYPE html><html><body>"];
    NSString *str1 = [Base64 encode:UIImagePNGRepresentation(imageView.image)];
    
    [body appendString:@"<h2>ID Card</h2>"];
    [body appendFormat:@"<img src=\"data:image/png;base64,%@\" alt=\"\" height=\"100\" width=\"100\"/>",str1];
    
    [body appendFormat:@"<p>%@ %@</p>", nameField.text, districtField.text];
   
    [body appendString:@"</body></html>"];
    return body;
}


-(IBAction)list:(id)sender{
    DetailViewController *anotherViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"anotherViewController22"];
    
   // [UIView beginAnimations:nil context:NULL];
    
   // [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:YES];
    //[UIView setAnimationDuration:.8];
    [self.navigationController pushViewController:anotherViewController animated:YES];
    //[anotherViewController release];
    //[UIView commitAnimations];
    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"edit"];
    imageView.image=[UIImage imageNamed:@"noimage.jpeg"];
    nameField.text=@"";
    districtField.text=@"";
    emailField.text=@"";
    mobileField.text=@"";
}


@end