Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import "NewInvoiceViewController.h"
  2.  
  3. @interface NewInvoiceViewController ()
  4.  
  5. @end
  6.  
  7. @implementation NewInvoiceViewController
  8.  
  9. @synthesize clientLabel, clientPicker, clientPickerViewContainer, clientStaticCell, clientPickerConstraint;
  10.  
  11. - (id)initWithStyle:(UITableViewStyle)style
  12. {
  13.     self = [super initWithStyle:style];
  14.     if (self) {
  15.         // Custom initialization
  16.     }
  17.     return self;
  18. }
  19.  
  20. - (void)setClientLabelText {
  21.     clientLabel.text = [storedClients objectAtIndex:[clientPicker selectedRowInComponent:0]];
  22. }
  23.  
  24. - (void)showClientPickerUIView
  25. {
  26.     [UIView animateWithDuration:.5 animations:^{
  27.        
  28.         clientPickerConstraint.constant = 0;
  29.         [self.view layoutIfNeeded];
  30.        
  31.     } completion:nil];
  32. }
  33.  
  34. - (void)cancelClientPickerUIView
  35. {
  36.     [UIView animateWithDuration:.5 animations:^{
  37.        
  38.         clientPickerConstraint.constant = 260;
  39.         [self.view layoutIfNeeded];
  40.        
  41.     } completion:nil];
  42. }
  43.  
  44. - (void)doneClientPickerUIView
  45. {
  46.     [UIView animateWithDuration:.5 animations:^{
  47.        
  48.         clientPickerConstraint.constant = 260;
  49.         [self.view layoutIfNeeded];
  50.        
  51.     } completion:^ (BOOL finished){
  52.         if (finished) {
  53.             [self setClientLabelText];
  54.             // Cell will be deselected by following line.
  55.             [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
  56.         }
  57.     }];
  58. }
  59.  
  60. -(void)viewDidLayoutSubviews
  61. {
  62.     clientPickerConstraint.constant = 260;
  63. }
  64.  
  65. - (void)viewDidLoad
  66. {
  67.     [super viewDidLoad];
  68.  
  69.     storedClients = [NSArray arrayWithObjects:@"Joe Smith",@"John Doe",@"Bob Johnson",@"Joel Smith", nil];
  70.    
  71.     // Uncomment the following line to preserve selection between presentations.
  72.     // self.clearsSelectionOnViewWillAppear = NO;
  73.  
  74.     // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
  75.     // self.navigationItem.rightBarButtonItem = self.editButtonItem;
  76. }
  77.  
  78. - (void)didReceiveMemoryWarning
  79. {
  80.     [super didReceiveMemoryWarning];
  81.     // Dispose of any resources that can be recreated.
  82. }
  83.  
  84. - (IBAction)cancel:(id)sender{
  85.     [self.navigationController dismissViewControllerAnimated:YES completion:nil];
  86. }
  87.  
  88. - (IBAction)clientSelectCancel:(id)sender {
  89.     [self cancelClientPickerUIView];
  90. }
  91.  
  92. - (IBAction)clientSelectDone:(id)sender {
  93.     [self doneClientPickerUIView];
  94. }
  95.  
  96. // returns the number of 'columns' to display.
  97. - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
  98. {
  99.     return 1;
  100. }
  101.  
  102. // returns the # of rows in each component..
  103. - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
  104. {
  105.     return [storedClients count];
  106. }
  107.  
  108. -(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
  109.     return [storedClients objectAtIndex:row];
  110. }
  111.  
  112. -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
  113.    
  114.     selectedClient = [storedClients objectAtIndex:row];
  115.    
  116.    
  117. }
  118.  
  119. #pragma mark - Table view delegate
  120.  
  121. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  122. {
  123.     if([tableView cellForRowAtIndexPath:indexPath] == self.clientStaticCell){
  124.         [self showClientPickerUIView];
  125.     }  
  126. }
  127.  
  128. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement