Wednesday, 20 January 2016

UISearchBar in Table View

UISearchBar in Table View


1) Set Your Storyboard Like This :




2) Write This Code in ViewController.h :



#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate , UISearchBarDelegate>
{
    int flgTemp;


    NSMutableDictionary *dic_data;

}
@property(strong,nonatomic)IBOutlet UITableView *tblobj;

@property(strong,nonatomic)IBOutlet UISearchBar* search ;

@property(strong,nonatomic)NSMutableArray *arrObj ;


@property(strong,nonatomic)NSMutableArray *arrImage ;

@property(strong,nonatomic)NSMutableArray *searchResults ;


@end




3) Write This Code in ViewController.m :

Note :- Here Two Method For Search :-

---> 1) For Search Between Word Also :-


#import "ViewController.h"


@interface ViewController ()

@end

@implementation ViewController
@synthesize arrObj,search,tblobj,searchResults, arrImage ;

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    arrObj  = [[NSMutableArray alloc] initWithObjects:@"Accounting",@"Airport",@"Amusement Park",@"Aquarium",@"Art Gallery",@"Atm",@"Bakery",@"Bank",@"Bar",@"Beauty Salon",@"Bicycle Store",@"Book Store",@"Bowling Alley",@"Bus Station",@"Cafe",@"Campground",@"Car Dealer",@"Car Rental",@"Car Rrepair",@"Car Wash",@"Casino",@"Cemetery",@"Church",@"City Hall",@"Clothing Store",@"Convenience Store",@"Courthouse",@"Dentist",@"Department Store",@"Doctor",@"Electrician",@"Electronics Store",@"Embassy",@"Establishment",@"Finance",@"Fire Station",@"Florist",@"Food",@"Funeral Home",@"Furniture Store",@"Gas Station",@"General Contractor",@"Grocery Or market",@"Gym",@"Hair Care",@"Hardware Store",@"Health",@"Hindu Temple",@"Home Goods Store",@"Hospital",@"Insurance Agency",@"Jewelry Store",@"Laundry",@"Lawyer",@"Library",@"Liquor Store",@"Local Government Office",@"Locksmith",@"Lodging",@"Meal Lelivery",@"Meal Takeaway",@"Mosque",@"Movie rental",@"Movie Theater",@"Moving Company",@"Museum",@"Night Club",@"Painter",@"Park",@"Parking",@"Pet Store",@"Pharmacy",@"Physiotherapist",@"Place Of Worship",@"Plumber",@"Police",@"Post Office",@"Real Estate Agency",@"Restaurant",@"Roofing Contractor",@"Rv Park",@"School",@"Shoe Store",@"Shopping Mall",@"Spa",@"Stadium",@"Storage",@"Store",@"Subway Station",@"Synagogue",@"Taxi Stand",@"Train Station",@"Travel Agency",@"University",@"Veterinary Care",@"Zoo", nil];
    
 arrImage = [[NSMutableArray alloc] initWithObjects:@"1.png",@"2.png",@"3.png",@"4.png",@"5.png",@"6.png",@"7.png",@"8.png",@"9.png",@"10.png",@"11.png",@"12.png",@"13.png",@"14.png",@"15.png",@"16.png",@"17.png",@"18.png",@"19.png",@"20.png",@"21.png",@"22.png",@"23.png",@"24.png",@"25.png",@"26.png",@"27.png",@"28.png",@"29.png",@"30.png",@"31.png",@"32.png",@"33.png",@"34.png",@"35.png",@"36.png",@"37.png",@"38.png",@"39.png",@"40.png",@"41.png",@"42.png",@"43.png",@"44.png",@"45.png",@"46.png",@"47.png",@"48.png",@"49.png",@"50.png",@"51.png",@"52.png",@"53.png",@"54.png",@"55.png",@"56.png",@"57.png",@"58.png",@"59.png",@"60.png",@"61.png",@"62.png",@"63.png",@"64.png",@"65.png",@"66.png",@"67.png",@"68.png",@"69.png",@"70.png",@"71.png",@"72.png",@"73.png",@"74.png",@"96.png",@"95.png",@"75.png",@"76.png",@"77.png",@"78.png",@"79.png",@"80.png",@"81.png",@"82.png",@"83.png",@"84.png",@"85.png",@"86.png",@"87.png",@"88.png",@"89.png",@"90.png",@"91.png",@"92.png",@"93.png",@"94.png",nil];
    
    
        NSLog(@"%lu, %lu", (unsigned long)arrObj.count,(unsigned long)arrImage.count);
    

        dic_data=[[NSMutableDictionary alloc]initWithObjects:arrImage forKeys:arrObj];

    searchResults = [[NSMutableArray alloc] init];
   
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (flgTemp==1)
    {
        return searchResults.count ;
    }
    else
    {
       return arrObj.count ;

    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    if (flgTemp==1)
    {
        cell.textLabel.text = [searchResults objectAtIndex:indexPath.row];
    
        NSString *imgname=[dic_data valueForKey:[searchResults objectAtIndex:indexPath.row]];
    
        cell.imageView.image = [UIImage imageNamed:imgname];
    }
    else
    {
        cell.textLabel.text = [arrObj objectAtIndex:indexPath.row];
        
        cell.imageView.image = [arrImage objectAtIndex:indexPath.row];
    }
    return cell ;
    
}



- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
   
    flgTemp = 1 ;
    [searchResults removeAllObjects];
    
    NSString *mainArrayItem ;
    NSRange range;

    
    if (![searchText isEqualToString:@""])
    {
        for (int i=0; i< arrObj.count; i++)
        {
            mainArrayItem = [arrObj objectAtIndex:i];
            range =[mainArrayItem rangeOfString:searchText options:NSCaseInsensitiveSearch];
            
            if (range.length>0)
            {
                [searchResults addObject:[arrObj objectAtIndex:i]];
            }
        }
        [tblobj reloadData];
    }
    else
    {
        flgTemp = 0;
        [tblobj reloadData];
        
    }

}


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

@end


---> 2) For Search Only Starting Word :-


#import "ViewController.h"


@interface ViewController ()

@end

@implementation ViewController
@synthesize arrObj,search,tblobj,searchResults ;

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    arrObj  = [[NSMutableArray allocinitWithObjects:@"Accounting",@"Airport",@"Amusement Park",@"Aquarium",@"Art Gallery",@"Atm",@"Bakery",@"Bank",@"Bar",@"Beauty Salon",@"Bicycle Store",@"Book Store",@"Bowling Alley",@"Bus Station",@"Cafe",@"Campground",@"Car Dealer",@"Car Rental",@"Car Rrepair",@"Car Wash",@"Casino",@"Cemetery",@"Church",@"City Hall",@"Clothing Store",@"Convenience Store",@"Courthouse",@"Dentist",@"Department Store",@"Doctor",@"Electrician",@"Electronics Store",@"Embassy",@"Establishment",@"Finance",@"Fire Station",@"Florist",@"Food",@"Funeral Home",@"Furniture Store",@"Gas Station",@"General Contractor",@"Grocery Or market",@"Gym",@"Hair Care",@"Hardware Store",@"Health",@"Hindu Temple",@"Home Goods Store",@"Hospital",@"Insurance Agency",@"Jewelry Store",@"Laundry",@"Lawyer",@"Library",@"Liquor Store",@"Local Government Office",@"Locksmith",@"Lodging",@"Meal Lelivery",@"Meal Takeaway",@"Mosque",@"Movie rental",@"Movie Theater",@"Moving Company",@"Museum",@"Night Club",@"Painter",@"Park",@"Parking",@"Pet Store",@"Pharmacy",@"Physiotherapist",@"Place Of Worship",@"Plumber",@"Police",@"Post Office",@"Real Estate Agency",@"Restaurant",@"Roofing Contractor",@"Rv Park",@"School",@"Shoe Store",@"Shopping Mall",@"Spa",@"Stadium",@"Storage",@"Store",@"Subway Station",@"Synagogue",@"Taxi Stand",@"Train Station",@"Travel Agency",@"University",@"Veterinary Care",@"Zoo"nil];
    
    searchResults = [[NSMutableArray allocinit];
   
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (flgTemp==1)
    {
        return searchResults.count ;
    }
    else
    {
       return arrObj.count ;

    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    if (cell == nil)
    {
        cell = [[UITableViewCell allocinitWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    if (flgTemp==1)
    {
         cell.textLabel.text = [searchResults objectAtIndex:indexPath.row];    }
    else
    {
        cell.textLabel.text = [arrObj objectAtIndex:indexPath.row];
    }
    return cell ;
    
}

-(void)filterContantForSearchText:(NSString *)searchText scope:(NSString *)scope
{
    
    
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@",searchText];
    
    NSArray *tempArray = [arrObj filteredArrayUsingPredicate:predicate];
    
    searchResults = [NSMutableArray arrayWithArray:tempArray];
    
    [tblobj reloadData];
}

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
    searchBar.showsCancelButton = YES;
    return YES;
}

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
{
    searchBar.showsCancelButton = NO;
    return YES;
}

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
    if ([searchText isEqualToString:@""]||searchText==nil )
    {
        flgTemp = 0 ;
        [tblobj reloadData];
    }
    else
    {
        flgTemp = 1 ;
        [self filterContantForSearchText:searchText scope:@"Al"];
    }

}


- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar
{
    [searchBar resignFirstResponder];
}


- (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    
    if([text isEqualToString:@"\n"])
    {
        [searchBar resignFirstResponder];
        return NO;
    }
    return YES;
}


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

@end
















Friday, 8 January 2016

Motion Detection

Motion Detection


add framework :-  CoreMotion.framework

.h File :-


#import <CoreMotion/CMMotionActivityManager.h>
#import <CoreMotion/CMMotionActivity.h>
#import <CoreMotion/CMStepCounter.h>

@interface ViewController : UIViewController
{
    CMMotionActivityManager *motionActivityManager;
}

@end


.m File :-

View DidLoad or ViewWillAppear
[self check_MotionDetector];

#pragma mark - Motion Detection
-(void)check_MotionDetector
{
    motionActivityManager = [[CMMotionActivityManager allocinit];
    [motionActivityManager startActivityUpdatesToQueue:[[NSOperationQueuealloc]init]withHandler:^(CMMotionActivity *activity) {
        dispatch_async(dispatch_get_main_queue(), ^{
            if ([activity running])
            {
                [self doExit:@"Automotive"];
            }
            else if ([activity cycling])
            {
                [self doExit:@"Automotive"];
            }
            else if ([activity automotive])
            {
                [self doExit:@"Automotive"];
            }
        });
    }];
}

-(void)doExit:(NSString *)MotionType
{
    if ([MotionType isEqualToString:@"Automotive"])
    {
        UIAlertView *alert = [[UIAlertView allocinitWithTitle:@"Confirmation"
                                                        message:@"Do you drive the car?"
                                                       delegate:self
                                              cancelButtonTitle:@"No"
                                              otherButtonTitles:@"Yes"nil];
        [alert show];
        [alert setTag:100];
    }
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag == 100)
    {
        if (buttonIndex == 0)
        {
            [motionActivityManager stopActivityUpdates];
        }
        else if (buttonIndex == 1)
        {
            //home button press programmatically
            UIApplication *app = [UIApplication sharedApplication];
            [app performSelector:@selector(suspend)];
            
            //wait 2 seconds while app is going background
            [NSThread sleepForTimeInterval:1.0];
            
            //exit app when app is in background
            exit(0);
        }
    }
}

Screen Shot for View

Screen Shot for View


  Add the Framework : QuartzCore.framework
           
 .h File:

              #import <QuartzCore/QuartzCore.h>


 .m File (Button for CaptureImage):

             //Coding for Screen Shot for View(saved to Photo Library in Your Device)

                       UIGraphicsBeginImageContext(self.view.frame.size);
                       [[self.view layerrenderInContext:UIGraphicsGetCurrentContext()];
                       UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
                       UIGraphicsEndImageContext();
                      //Save Image to Local Library
                      UIImageWriteToSavedPhotosAlbum(screenshotself,@selector(image:didFinishSavingWithError:contextInfo:), nil);


- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    UIAlertView *alert;
    if (error)
    {
        alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                           message:@"Unable to save image to Photo Album."
                                          delegate:self cancelButtonTitle:@"Ok"
                                 otherButtonTitles:nil];
    }
    else
    {
        alert = [[UIAlertView alloc] initWithTitle:@"Success"
                                           message:@"Image saved to Photo Album."
                                          delegate:self cancelButtonTitle:@"Ok"
                                 otherButtonTitles:nil];
    }
    [alert show];
    
}

SOAP XML Webservice Implementation

SOAP XML Webservice Implementation



.h File :-

@interface DetailViewController : UIViewController<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate>
{
    
    
    IBOutlet UIDatePicker *datepicker;
    IBOutlet UIDatePicker *datepicker1;
    
    IBOutlet UIButton *btn;
    
    IBOutlet UIButton *date1;
    IBOutlet UIButton *date2;
    
    IBOutlet UITextField *schedule;
    IBOutlet UITextField *reason;
    IBOutlet UITextField *approxdate2;
    IBOutlet UITextField *PhyType;
    IBOutlet UITextField *PhyName;
    
    NSString *schedule1;
    NSString *reason1;
    NSString *approxdate1;
    NSString *PhyType1;
    NSString *PhyName1;
    
    IBOutlet UIAlertView *alert;
    
    NSMutableData *webData;
    NSMutableString *soapResults;
    NSXMLParser *xmlParser;
    BOOL *recordResults;
    
    IBOutlet UIButton *PhysicianTypeList;
    IBOutlet UIButton *PhysicianNameList;
    
    NSString *string;
    
    NSString *PatID;
    
    NSMutableString *capturedCharacters ;
    
    NSURLConnection *conn;
    NSString * qelementName;
    NSString * RequestStep;
    
    NSMutableArray *ArrayTypeList;
    NSMutableArray *NameList;
    NSMutableArray *IDList;
    NSMutableArray *ClinicList;
    
    IBOutlet UITableView *table1;
    IBOutlet UITableView *table2;
}

@property(nonatomic,retain)IBOutlet UIAlertView *alert;

@property(nonatomic,retain)IBOutlet NSString *parsedString;

@property(nonatomic,retain)NSString *string;

@property(nonatomic,retain)IBOutlet UITableView *table1;
@property(nonatomic,retain)IBOutlet UITableView *table2;

@property(nonatomic,retain)IBOutlet UIButton *PhysicianTypeList;
@property(nonatomic,retain)IBOutlet UIButton *PhysicianNameList;

@property(nonatomic,retain)NSString *PatID;
@property(nonatomic,retain)NSString *schedule1;
@property(nonatomic,retain)NSString *reason1;
@property(nonatomic,retain)NSString *approxdate1;
@property(nonatomic,retain)NSString *PhyType1;
@property(nonatomic,retain)NSString *PhyName1;

@property (retain, nonatomic) id detailItem;

@property(nonatomic,retain) IBOutlet UIDatePicker *datepicker;

@property(nonatomic,retain) IBOutlet UIDatePicker *datepicker1;

@property(nonatomic,retain) IBOutlet UITextField *schedule;

@property(nonatomic,retain) IBOutlet UITextField *reason;

@property(nonatomic,retain) IBOutlet UITextField *approxdate2;

@property(nonatomic,retain) IBOutlet UITextField *PhyType;

@property(nonatomic,retain) IBOutlet UITextField *PhyName;


@property (retain, nonatomic) IBOutlet UILabel *detailDescriptionLabel;

-(IBAction)btn:(id)sender;
-(IBAction)displaydate:(id)sender;
-(IBAction)displaydate1:(id)sender;
-(IBAction)pickerdate:(id)sender;
-(IBAction)pickerdate1:(id)sender;

-(IBAction)PhysicianType:(id)sender;
-(IBAction)PhysicianName:(id)sender;

@end


.m File :-



#import "DetailViewController.h"
#import "patientdetails.h"
#import "GANTracker.h"

@interface DetailViewController ()
- (void)configureView;
@end

@implementation DetailViewController

@synthesize detailItem ;
@synthesize detailDescriptionLabel,datepicker,datepicker1;
@synthesize schedule,reason,PhyName,PhyType,approxdate2;
@synthesize schedule1,reason1,PhyType1,PhyName1,approxdate1;
@synthesize alert,PatID;
@synthesize PhysicianNameList,PhysicianTypeList;
@synthesize string;
@synthesize parsedString;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        self = [super initWithNibName:@"DetailViewController_iPad" bundle:nibBundleOrNil];
        if (self
        {
            self.title = NSLocalizedString(@"Admission"@"Admission");
        }
    }
    else
    {
        self = [super initWithNibName:@"DetailViewController_iPhone" bundle:nibBundleOrNil];
        self.title = NSLocalizedString(@"Admission"@"Admission");
        
    }
    return self;
}
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField 
{
    [schedule resignFirstResponder];
    [reason resignFirstResponder];
    [PhyType resignFirstResponder];
    [PhyName resignFirstResponder];
    [approxdate2 resignFirstResponder];
return YES;
}

- (void)dealloc
{
    [detailItem release];
    [detailDescriptionLabel release];
    [super dealloc];
}

#pragma mark - Managing the detail item

- (void)setDetailItem:(id)newDetailItem
{
    if (detailItem != newDetailItem) {
        [detailItem release]; 
        detailItem = [newDetailItem retain]; 
        [self configureView];
    }

          
}

- (void)configureView
{
        if (self.detailItem) {
        self.detailDescriptionLabel.text = [self.detailItem description];
    }
}



-(IBAction)pickerdate:(id)sender
{
    datepicker.hidden=NO;
    [datepicker becomeFirstResponder];
}


-(IBAction)pickerdate1:(id)sender
{
    datepicker1.hidden=NO;
    [datepicker1 becomeFirstResponder];
}


-(IBAction)displaydate:(id)sender;
{
    NSDateFormatter *dt1=[[NSDateFormatter alloc]init];
    [dt1 setFormatterBehavior:NSDateFormatterBehavior10_4];
    [dt1 setDateStyle:NSDateFormatterMediumStyle];
    [dt1 setDateFormat:@"yyyy-MM-dd"];
    schedule.text=[NSString stringWithFormat:@"%@",[dt1 stringFromDate:datepicker.date]];
    datepicker.hidden=YES;
}


-(IBAction)displaydate1:(id)sender;
{
    NSDateFormatter *dt2=[[NSDateFormatter alloc]init];
    [dt2 setFormatterBehavior:NSDateFormatterBehavior10_4];
    [dt2 setDateStyle:NSDateFormatterMediumStyle];
    [dt2 setDateFormat:@"yyyy-MM-dd"];
    approxdate2.text=[NSString stringWithFormat:@"%@",[dt2stringFromDate:datepicker1.date]];
    datepicker1.hidden=YES;
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
   
}


-(IBAction)PhysicianType:(id)sender
{
    string=@"TypeList";
    
    NSString *soapMessage = [NSString stringWithFormat:
                             @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
                             "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
                             "<soap:Body>\n"
                             "<MedApp_PhyType xmlns=\"http://www.iwedplanner.com/\"/>\n"
                             "</soap:Body>\n"
                             "</soap:Envelope>\n"];
    
    NSLog(soapMessage);
    
    NSURL *url = [NSURLURLWithString:@"http://www.iwedplanner.com/MedicalRecords/MedApp_Physician.asmx?op=MedApp_PhyType"];
    
    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
    
    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
    
    
    [theRequest addValue@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [theRequest addValue@"http://www.iwedplanner.com/MedApp_PhyType"forHTTPHeaderField:@"SOAPAction"];
    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
    
    NSURLConnection *theConnection = [[NSURLConnection allocinitWithRequest:theRequestdelegate:self];
    
    if( theConnection )
    {
        webData = [[NSMutableData dataretain];
    }
    else
    {
        NSLog(@"theConnection is NULL");
    }
}


-(IBAction)PhysicianName:(id)sender
{
    string=@"NameList";
    
    PhyType1=PhyType.text;
    NSLog(PhyType1);
    if([PhyType.text length]==0)
    {
        
        UIAlertView *alert=[[UIAlertView alloc]
                            initWithTitle:@"Message!"
                            message:@"First Enter Physician Type"
                            delegate:self
                            cancelButtonTitle:@"OK"
                            otherButtonTitles:nil];
        [alert show];
        [alert release];
        
    }
    else
    {
        NSString *soapMessage = [NSString stringWithFormat:
                                 @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
                                 "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
                                 "<soap:Body>\n"
                                 "<MedApp_PhysTypeDetails xmlns=\"http://www.iwedplanner.com/\">\n"
                                 "<PhyType>%@</PhyType>\n"
                                 "</MedApp_PhysTypeDetails>\n"
                                 "</soap:Body>\n"
                                 "</soap:Envelope>\n",PhyType1];
        
        NSLog(soapMessage);
        
        NSURL *url = [NSURLURLWithString:@"http://www.iwedplanner.com/MedicalRecords/MedApp_Physician.asmx?op=MedApp_PhysTypeDetails"];
        
        NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
        
        NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
        
        
        [theRequest addValue@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
        [theRequest addValue@"http://www.iwedplanner.com/MedApp_PhysTypeDetails"forHTTPHeaderField:@"SOAPAction"];
        [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
        [theRequest setHTTPMethod:@"POST"];
        [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
        
        NSURLConnection *theConnection = [[NSURLConnection alloc]initWithRequest:theRequest delegate:self];
        
        if( theConnection )
        {
            webData = [[NSMutableData dataretain];
        }
        else
        {
            NSLog(@"theConnection is NULL");
        }

    }
}


#pragma mark - View lifecycle

- (void)viewDidLoad
{
    ArrayTypeList =[[NSMutableArray alloc]init];
    NameList =[[NSMutableArray alloc]init];
    IDList =[[NSMutableArray alloc]init];
    ClinicList =[[NSMutableArray alloc]init];
    
    
    string=@"Default";
    
    table1.hidden=YES;
    table2.hidden=YES;
    
    NSLog(PatID);
    
    
    self.title=@"PatientDetails";
    schedule.text=@"";
    reason.text=@"";
    approxdate2.text=@"";
    PhyType.text=@"";
    PhyName.text=@"";
   
    
    NSError *error;
    [[GANTracker sharedTrackerstartTrackerWithAccountID:@"UA-10190539-28"
  dispatchPeriod:10
delegate:nil];
//NSError *error;
    if (![[GANTracker sharedTrackertrackPageview:@"/MedApp_ApptmtDetails"withError:&error]) {
// Handle error here
}  
    
    UIBarButtonItem *add=[[UIBarButtonItem alloc]initWithTitle:@"Home"style:UIBarButtonSystemItemFlexibleSpace target:self action:@selector(home)];                         self.navigationItem.rightBarButtonItem=add;
    
    
    schedule.placeholder=@"Enter Date";
    datepicker.transform=CGAffineTransformMakeScale(1.01.0);
    datepicker.hidden=YES;
    [datepicker setDatePickerMode:UIDatePickerModeDate];
    approxdate2.placeholder=@"Enter Date";
    datepicker1.transform=CGAffineTransformMakeScale(1.01.0);
    datepicker1.hidden=YES;
    [datepicker1 setDatePickerMode:UIDatePickerModeDate];
    
    schedule.delegate=self;
    reason.delegate=self;
    approxdate2.delegate=self;
    PhyType.delegate=self;
    PhyName.delegate=self;
    
    [super viewDidLoad];
    
    
}

-(void)home
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(IBAction)btn:(id)sender
{
    string=@"Default";

    schedule1=schedule.text;
    reason1=reason.text;
    approxdate1=approxdate2.text;
    PhyType1=PhyType.text;
    PhyName1=PhyName.text;
    
    if([approxdate1 isEqual:@""])
    {
        approxdate1=@"";
    }
    
    NSLog(PatID);
    NSLog(schedule1);
    NSLog(reason1);
    NSLog(approxdate1);
    NSLog(PhyType1);
    NSLog(PhyName1);
    
    if (([schedule.text length]==0) && ([reason.text length]==0) && ([approxdate2.textlength]==0) && ([PhyType.text length]==0) && ([PhyName.text length]==0)) 
    {
        UIAlertView *alert=[[UIAlertView alloc]
                            initWithTitle:@"Message!"
                            message:@"Fill Empty Fields"
                            delegate:self
                            cancelButtonTitle:@"OK"
                            otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    else if([schedule.text length]==0)
    {
        UIAlertView *alert=[[UIAlertView alloc]
                            initWithTitle:@"Message!"
                            message:@"Enter Schedule Date"
                            delegate:self
                            cancelButtonTitle:@"OK"
                            otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    
    else if([reason.text length]==0)
    {
        UIAlertView *alert=[[UIAlertView alloc]
                            initWithTitle:@"Message!"
                            message:@"Enter Reason"
                            delegate:self
                            cancelButtonTitle:@"OK"
                            otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    
    else if([approxdate2.text length]==0)
    {
        
        UIAlertView *alert=[[UIAlertView alloc]
                            initWithTitle:@"Message!"
                            message:@"Enter Approximate date on Symptom"
                            delegate:self
                            cancelButtonTitle:@"OK"
                            otherButtonTitles:nil];
        [alert show];
        [alert release];

    }
    
    else if([PhyType.text length]==0)
    {
        
        UIAlertView *alert=[[UIAlertView alloc]
                            initWithTitle:@"Message!"
                            message:@"Enter Physician Type"
                            delegate:self
                            cancelButtonTitle:@"OK"
                            otherButtonTitles:nil];
        [alert show];
        [alert release];
        
    }
    
    else if([PhyName.text length]==0)
    {
        
        UIAlertView *alert=[[UIAlertView alloc]
                            initWithTitle:@"Message!"
                            message:@"Enter Physician Name"
                            delegate:self
                            cancelButtonTitle:@"OK"
                            otherButtonTitles:nil];
        [alert show];
        [alert release];
        
    }
    
    else
    {
        NSString *soapMessage = [NSString stringWithFormat:
                                 @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
                                 "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
                                 "<soap:Body>\n"
                                 "<MedApp_AdmissionInsert xmlns=\"http://www.iwedplanner.com/\">\n"
                                 "<PatID>%@</PatID>\n"
                                 "<AdmDate>%@</AdmDate>\n"
                                 "<ReasonAdm>%@</ReasonAdm>\n"
                                 "<SymptonsDate>%@</SymptonsDate>\n"
                                 "<PhyID>%@</PhyID>\n"
                                 "</MedApp_AdmissionInsert>\n"
                                 "</soap:Body>\n"
                                 "</soap:Envelope>\n",PatID,schedule1,reason1,approxdate1,PhyName1];
        
        NSLog(soapMessage);
        
        NSURL *url = [NSURLURLWithString:@"http://www.iwedplanner.com/MedicalRecords/MedApp_Admission.asmx?op=MedApp_AdmissionInsert"];
        
        NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
    
        NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

        
        [theRequest addValue@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
        [theRequest addValue@"http://www.iwedplanner.com/MedApp_AdmissionInsert"forHTTPHeaderField:@"SOAPAction"];
        [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
        [theRequest setHTTPMethod:@"POST"];
        [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
        
        NSURLConnection *theConnection = [[NSURLConnection alloc]initWithRequest:theRequest delegate:self];
        
        if( theConnection )
        {
            webData = [[NSMutableData dataretain];
        }
        else
        {
            NSLog(@"theConnection is NULL");
        }
    }    
}


-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse*)response
{
[webData setLength0];
}


-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
}


-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"ERROR with theConenction");
[connection release];
[webData release];
    
}


-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    if ([string isEqualToString:@"TypeList"]) 
    {
        NSLog(@" webdate%@",webData);
        NSLog(@"DONE. Received Bytes: %d", [webData length]);
        NSString *theXML = [[NSString allocinitWithBytes: [webData mutableByteslength:[webData lengthencoding:NSUTF8StringEncoding];
        NSLog(theXML);
        
        [theXML release];
        
        ifxmlParser )
        {
            [xmlParser release];
        }
        
        xmlParser = [[NSXMLParser allocinitWithDatawebData];
        [xmlParser setDelegateself];
        [xmlParser setShouldResolveExternalEntitiesYES];
        [xmlParser parse];
        
        [connection release];
        [webData release];
    }
    else if ([string isEqualToString:@"NameList"])
    {
        NSLog(@" webdate%@",webData);
        NSLog(@"DONE. Received Bytes: %d", [webData length]);
        NSString *theXML = [[NSString allocinitWithBytes: [webData mutableByteslength:[webData lengthencoding:NSUTF8StringEncoding];
        NSLog(theXML);
        
        [theXML release];
        
        ifxmlParser )
        {
            [xmlParser release];
        }
        
        xmlParser = [[NSXMLParser allocinitWithDatawebData];
        [xmlParser setDelegateself];
        [xmlParser setShouldResolveExternalEntitiesYES];
        [xmlParser parse];
        
        [connection release];
        [webData release];
    }
    else
    {
        NSLog(@"DONE. Received Bytes: %d", [webData length]);
        NSString *theXML = [[NSString allocinitWithBytes: [webData mutableByteslength:[webData lengthencoding:NSUTF8StringEncoding];
        NSLog(theXML);
        
        NSArray *components1 = [theXML componentsSeparatedByString:@"|"];
        NSString *name1 = [components1 objectAtIndex:1];
        NSLog(name1);
        
        NSArray *components2 = [theXML componentsSeparatedByString:@"|"];
        PatID = [components2 objectAtIndex:2];
        NSLog(PatID);
        
        NSString *name3=[NSString stringWithFormat:@"Details are Sucessfully Saved.Your Patient ID : %@",PatID];
        
        
        
        if ([name1 hasPrefix:@"Pa"]) 
        {
            alert=[[UIAlertView alloc]
                   initWithTitle:@"Message!"
                   message:name3
                   delegate:self
                   cancelButtonTitle:nil
                   otherButtonTitles:@"OK",nil];
            [alert setTag:1];
            [alert show];
            [alert release];
        }
        else
        {
            alert=[[UIAlertView alloc]
                   initWithTitle:@"Message!"
                   message:@"Details are Not Saved"
                   delegate:self
                   cancelButtonTitle:@"OK"
                   otherButtonTitles:nil];
            [alert show];
            [alert release];
        }
        
        [theXML release];
        
        ifxmlParser )
        {
            [xmlParser release];
        }
        
        xmlParser = [[NSXMLParser allocinitWithDatawebData];
        [xmlParser setDelegateself];
        [xmlParser setShouldResolveExternalEntitiesYES];
        [xmlParser parse];
        
        [connection release];
        [webData release];
    }
}

-(void)alertView:(UIAlertView *)objAlert didDismissWithButtonIndex:(NSInteger)buttonIndex 
{
    if([alert tag]==1)
    {
        if (buttonIndex==0)
        {
            /*NSLog(PatID);
            patientdetails *pat=[[patientdetails alloc]init];
            pat.MaternityPatient1=MaternityPatient;
            NSLog([compose objectAtIndex:0]);
            pat.PatID=[compose objectAtIndex:0];
            [self.navigationController pushViewController:pat animated:YES];*/
            
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
}


- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict 
{
    if ([elementName isEqualToString:@"Phy_Type"]) 
    {
    
    }
    capturedCharacters = [[NSMutableString allocinitWithCapacity:50];
    capturedCharacters = [[NSMutableString allocinitWithCapacity:250];
    
    if ([elementName isEqualToString:@"Name"]) 
    {
        
    }
    capturedCharacters = [[NSMutableString allocinitWithCapacity:50];
    capturedCharacters = [[NSMutableString allocinitWithCapacity:250];
    
    if ([elementName isEqualToString:@"ClinicName"]) 
    {
        
    }
    capturedCharacters = [[NSMutableString allocinitWithCapacity:50];
    capturedCharacters = [[NSMutableString allocinitWithCapacity:250];
    
    if ([elementName isEqualToString:@"PhyID"]) 
    {
        
    }
    capturedCharacters = [[NSMutableString allocinitWithCapacity:50];
    capturedCharacters = [[NSMutableString allocinitWithCapacity:250];
}




- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 
{
    
    
    
    if ([elementName isEqualToString:@"Phy_Type"])
    {
        parsedString = capturedCharacters;
        NSLog(@" decription:%@"capturedCharacters);
        [ArrayTypeList addObject:capturedCharacters];
        //PhyType.text=capturedCharacters;
        table1.hidden=NO;
        [table1 reloadData];
    }
    
    if ([elementName isEqualToString:@"Name"])
    {
        parsedString = capturedCharacters;
        NSLog(@" decription:%@"capturedCharacters);
        [NameList addObject:capturedCharacters];
        //PhyType.text=capturedCharacters;
        table2.hidden=NO;
        [table2 reloadData];
    }

    if ([elementName isEqualToString:@"ClinicName"])
    {
        parsedString = capturedCharacters;
        NSLog(@" decription:%@"capturedCharacters);
        [ClinicList addObject:capturedCharacters];
    }

    if ([elementName isEqualToString:@"PhyID"])
    {
        parsedString = capturedCharacters;
        NSLog(@" decription:%@"capturedCharacters);
        [IDList addObject:capturedCharacters];
    }

    
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSMutableString *)string 
{
    if (capturedCharacters != nil
    {
        [capturedCharacters appendString:string];
        
    }
    else 
    {
        [capturedCharacters isEqual:string];
    }
    
}


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    datepicker.hidden=YES;
    datepicker1.hidden=YES;
    table1.hidden=YES;
    table2.hidden=YES;
    [schedule resignFirstResponder];
    [reason resignFirstResponder];
    [approxdate2 resignFirstResponder];
    [PhyType resignFirstResponder];
    [PhyName resignFirstResponder];
}


-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    datepicker.hidden=YES;
    datepicker1.hidden=YES;
    table1.hidden=YES;
    table2.hidden=YES;
    [schedule resignFirstResponder];
    [reason resignFirstResponder];
    [approxdate2 resignFirstResponder];
    [PhyType resignFirstResponder];
    [PhyName resignFirstResponder];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if(tableView == table1
    {
        return 1;
    }
    else if(tableView == table2
    {
        return 1;
    }    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    #warning Incomplete method implementation.
    // Return the number of rows in the section.
    if (tableView == table1
    {
        return [ArrayTypeList count];
    }
    
    else if (tableView == table2
    {
        return [NameList count];
    }
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell allocinitWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier] autorelease];
    }
    
    // Configure the cell.
    
    if(tableView == table1
    {
        cell.textLabel.text = [ArrayTypeList objectAtIndex:indexPath.row];
        
        return cell;
    }
    else if(tableView == table2)
    {
        cell.textLabel.text = [NameList objectAtIndex:indexPath.row];
        
        return cell;
    }
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
    if (tableView == table1
    {
        NSString *PhyTypes = [ArrayTypeList objectAtIndex:indexPath.row];
        PhyType.text=PhyTypes;
        table1.hidden=YES;
    }
    
    else if (tableView == table2
    {
        NSString *PhyNames = [NameList objectAtIndex:indexPath.row];
        PhyName.text=PhyNames;
        NSLog([IDList objectAtIndex:indexPath.row]);
        PatID=[IDList objectAtIndex:indexPath.row];
        table2.hidden=YES;
    }
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    
         return (interfaceOrientation == UIInterfaceOrientationPortrait);

}

@end



Build and Run the Application:



Click the PhysicianType ---> PhysicianTypeList is Loaded into Tableview --> table1

Click the PhysicianName ---> PhysicianNameList is Loaded into Tableview --> table2

Finnaly Click the Finish Button ---> save the all TextFields[except PhysicianTypeList,PhysicianName]              & PatID(Patient ID) is Saved.
                          The Field replaced in PhyID(Physician ID) is saved into url.