Advertisement
olcayertas

Untitled

Dec 8th, 2013
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. HMXSelectViewController.h
  2.  
  3. #import <UIKit/UIKit.h>
  4.  
  5. @interface HMXSelectViewController : UITableViewController
  6.  
  7. @property (strong, nonatomic) NSArray *items;
  8. @property (strong, nonatomic) UITextField *tergetTextField;
  9.  
  10. - (void)setItems:(NSArray *)array :(UITextField*)textField;
  11. - (void)returnToParent;
  12.  
  13. @end
  14.  
  15. HMXSelectViewController.m
  16.  
  17. #import "HMXSelectViewController.h"
  18.  
  19. @implementation HMXSelectViewController
  20.  
  21. - (id)initWithStyle:(UITableViewStyle)style{
  22.     self = [super initWithStyle:style];
  23.    
  24.     if (self) {
  25.        
  26.     }
  27.    
  28.     return self;
  29. }
  30.  
  31. - (void)viewDidLoad{
  32.     [super viewDidLoad];
  33. }
  34.  
  35. - (void)setItems:(NSArray *)array :(UITextField*)textField{
  36.     self.items = array;
  37.     self.tergetTextField = textField;
  38.    
  39. }
  40.  
  41. #pragma mark - Table view data source
  42.  
  43. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  44.     return 1;
  45. }
  46.  
  47. - (NSInteger)tableView:(UITableView *)tableView
  48.  numberOfRowsInSection:(NSInteger)section{
  49.     // Return the number of rows in the section.
  50.     return _items.count;
  51. }
  52.  
  53. - (UITableViewCell *)tableView:(UITableView *)tableView
  54.          cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  55.    
  56.     static NSString *CellIdentifier = @"Cell";
  57.    
  58.     UITableViewCell *cell =
  59.         [tableView
  60.          dequeueReusableCellWithIdentifier:CellIdentifier
  61.          forIndexPath:indexPath];
  62.    
  63.     UILabel *label = (UILabel*)[cell viewWithTag:2];
  64.     label.text = _items[indexPath.row];
  65.    
  66.     return cell;
  67. }
  68.  
  69. - (void)tableView:(UITableView *)tableView
  70. didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  71.     self.tergetTextField.text = self.items[indexPath.row];
  72.     [self performSelector:@selector(returnToParent) withObject:nil afterDelay:0.5];
  73.    
  74. }
  75.  
  76. - (void) returnToParent {
  77.     [self.navigationController popViewControllerAnimated:NO];
  78. }
  79.  
  80. @end
  81.  
  82. HMXNewCompanyViewController.h
  83.  
  84. #import <UIKit/UIKit.h>
  85. #import "HMXCompanyData.h"
  86. #import "HMXNewPersonnelData.h"
  87.  
  88. static HMXNewPersonnelData *newPersonelData;
  89.  
  90. @interface HMXNewCompanyViewController : UIViewController
  91.  
  92. @property (strong, nonatomic) IBOutlet UINavigationBar *navigationbar;
  93. @property (strong, nonatomic) IBOutlet UITextField *textFieldName;
  94. @property (strong, nonatomic) IBOutlet UITextField *textFieldPhone;
  95. @property (strong, nonatomic) IBOutlet UITextField *textFieldEmail;
  96. @property (strong, nonatomic) IBOutlet UITextField *textFieldUrl;
  97. @property (strong, nonatomic) IBOutlet UITextField *textFieldScale;
  98. @property (strong, nonatomic) IBOutlet UITextField *textFieldStatus;
  99. @property (strong, nonatomic) IBOutlet UITextView *textViewAddress;
  100. @property (strong, nonatomic) IBOutlet UITableView *tableViewPersonel;
  101. @property (strong, nonatomic) IBOutlet UITableView *tableViewNew;
  102. @property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
  103. @property (nonatomic) NSInteger step;
  104. @property (nonatomic) NSInteger selectedRow;
  105. @property (retain, nonatomic) HMXCompanyData *data;
  106. @property (strong, nonatomic) UITextField *activeField;
  107. @property (nonatomic) CGSize kbSize;
  108. @property (strong, nonatomic) NSArray *scales;
  109. @property (strong, nonatomic) NSArray *companyStatuses;
  110.  
  111. //- (void)setStep:(NSInteger)step;
  112. //- (void)setData:(HMXCompanyData *)newdata;
  113.  
  114. - (IBAction)backButtonClicked:(id)sender;
  115. - (IBAction)backgroundTouched:(id)sender;
  116. - (IBAction)scaleEditingDidBegin:(id)sender;
  117. - (IBAction)statusEditingDidBegin:(id)sender;
  118. - (IBAction)nextOneClicked:(id)sender;
  119. - (IBAction)addPersonelClicked:(id)sender;
  120.  
  121. @end
  122.  
  123. HMXNewCompanyViewController.m
  124.  
  125. #import "HMXNewCompanyViewController.h"
  126. #import "HMXCompanyData.h"
  127. #import "HMXNewPersonnelData.h"
  128. #import "HMXSelectViewController.h"
  129. #import "HMXAddDeparmentViewController.h"
  130.  
  131. int selectionSource;
  132.  
  133. @implementation HMXNewCompanyViewController
  134.  
  135. - (void)viewDidLoad{
  136.     [super viewDidLoad];
  137.     if([self.title isEqualToString:@"step1"]){
  138.         [self registerForKeyboardNotifications];
  139.         [self.scrollView
  140.          addGestureRecognizer:
  141.          [[UITapGestureRecognizer alloc]
  142.           initWithTarget:self
  143.           action:@selector(handleSingleTap:)]];
  144.         [self.navigationbar
  145.          addGestureRecognizer:
  146.          [[UITapGestureRecognizer alloc]
  147.           initWithTarget:self
  148.           action:@selector(handleSingleTap:)]];
  149.    
  150.         UIView* dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
  151.         _textFieldScale.inputView  = dummyView;
  152.         _textFieldStatus.inputView = dummyView;
  153.         self.textViewAddress.clipsToBounds = YES;
  154.         self.textViewAddress.layer.cornerRadius = 10.0f;
  155.         self.scales          = @[@"Mikro", @"Kobi", @"Büyük"];
  156.         self.companyStatuses = @[@"Aktif", @"Pasif"];
  157.     }
  158. }
  159.  
  160. - (void)handleSingleTap:(UITapGestureRecognizer*)sender {
  161.     if (sender.state == UIGestureRecognizerStateEnded){
  162.         [self backgroundTouched:self];
  163.     }
  164. }
  165.  
  166. - (void)registerForKeyboardNotifications {
  167.     [[NSNotificationCenter defaultCenter]
  168.      addObserver:self
  169.      selector:@selector(keyboardDidShow:)
  170.      name:UIKeyboardDidShowNotification object:nil];
  171.    
  172.     [[NSNotificationCenter defaultCenter]
  173.      addObserver:self
  174.      selector:@selector(keyboardWillHide:)
  175.      name:UIKeyboardWillHideNotification object:nil];
  176. }
  177.  
  178. - (void)keyboardDidShow:(NSNotification*)aNotification {
  179.     NSDictionary* info = [aNotification userInfo];
  180.     _kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
  181. }
  182.  
  183. - (void)keyboardWillHide:(NSNotification*)aNotification {
  184.     UIEdgeInsets contentInsets = UIEdgeInsetsZero;
  185.     _scrollView.contentInset = contentInsets;
  186.     _scrollView.scrollIndicatorInsets = contentInsets;
  187. }
  188.  
  189. - (void)addPersonel:(HMXNewPersonnelData *)personelData{
  190.     if(_data.personel == NULL)
  191.         _data.personel = [[NSMutableArray alloc] init];
  192.    
  193.     [_data.personel addObject:personelData.nameAndSurname];
  194.     [self.tableViewPersonel reloadData];
  195. }
  196.  
  197. - (IBAction)backButtonClicked:(id)sender {
  198.     [self.navigationController popViewControllerAnimated:YES];
  199. }
  200.  
  201. - (IBAction)backgroundTouched:(id)sender {
  202.     [self.view endEditing:YES];
  203. }
  204.  
  205. - (IBAction)scaleEditingDidBegin:(id)sender {
  206.     selectionSource = 0;
  207.     [self performSegueWithIdentifier:@"select" sender:self];
  208. }
  209.  
  210. - (IBAction)statusEditingDidBegin:(id)sender {
  211.     selectionSource = 1;
  212.     [self performSegueWithIdentifier:@"select" sender:self];
  213. }
  214.  
  215. - (IBAction)nextOneClicked:(id)sender {
  216.    
  217.     if (_textFieldName.text   == NULL ||
  218.         _textFieldPhone.text  == NULL ||
  219.         _textFieldEmail.text  == NULL ||
  220.         _textFieldUrl.text    == NULL ||
  221.         _textFieldScale.text  == NULL ||
  222.         _textViewAddress.text == NULL ||
  223.         _textFieldStatus.text == NULL) {
  224.         UIAlertView *alert =
  225.             [[UIAlertView alloc]
  226.              initWithTitle:nil
  227.              message:@"Lütfen boş alanları doldurup tekrar deneyin!"
  228.              delegate:self
  229.              cancelButtonTitle:@"Tamam"
  230.              otherButtonTitles:nil, nil];
  231.         [alert show];
  232.         return;
  233.     }
  234.    
  235.     if(_data == NULL)
  236.         _data = [[HMXCompanyData alloc] init];
  237.    
  238.     _data.name    = _textFieldName.text;
  239.     _data.phone   = _textFieldPhone.text;
  240.     _data.email   = _textFieldEmail.text;
  241.     _data.url     = _textFieldUrl.text;
  242.     _data.scale   = _textFieldScale.text;
  243.     _data.address = _textViewAddress.text;
  244.     _data.staus   = _textFieldStatus.text;
  245.     [self performSegueWithIdentifier:@"ekle" sender:self];
  246. }
  247.  
  248. - (IBAction)nextTwoClicked:(id)sender {
  249.     _step = 2;
  250.     [self performSegueWithIdentifier:@"ekle" sender:self];
  251. }
  252.  
  253. - (IBAction)addPersonelClicked:(id)sender {
  254.     [self performSegueWithIdentifier:@"addPersonel" sender:self];
  255. }
  256.  
  257. - (void)setData:(HMXCompanyData *)newdata{
  258.     self.data = newdata;
  259. }
  260.  
  261. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
  262. //    if ([[segue identifier] isEqualToString:@"ekle"]) {
  263. //        HMXAddDeparmentViewController *vc = [segue destinationViewController];
  264. //        [vc setData:_data];
  265. //    }
  266. //    else
  267.     if ([[segue identifier] isEqualToString:@"select"]){
  268.         HMXSelectViewController *vc = [segue destinationViewController];
  269.         if(selectionSource == 0)
  270.             [vc setItems:self.scales:self.textFieldScale];
  271.         else [vc setItems:self.companyStatuses:self.textFieldStatus];
  272.     }
  273. }
  274.  
  275. #pragma mark - Table view methods
  276.  
  277. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  278.     return 1;
  279. }
  280.  
  281. - (NSInteger)tableView:(UITableView *)tableView
  282.  numberOfRowsInSection:(NSInteger)section{
  283.    
  284.     if (tableView.tag == 1) {
  285.         return 3;
  286.     } else if (tableView.tag == 2){
  287.         return 2;
  288.     } else if(tableView.tag == 5){
  289.         NSLog(@"personel listesi: boyut :%d", _data.personel.count);
  290.         return _data.personel.count;
  291.     }
  292.    
  293.     return 0;
  294. }
  295.  
  296. - (UITableViewCell *)tableView:(UITableView *)tableView
  297.          cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  298.    
  299.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
  300.    
  301.     UILabel *label = (UILabel*)[cell viewWithTag:1];
  302.    
  303.     if (tableView.tag == 1) {
  304.         label.text = self.scales[indexPath.row];
  305.     } else if (tableView.tag == 2){
  306.         label.text = self.companyStatuses[indexPath.row];
  307.     } else if(tableView.tag == 5){
  308.         cell.textLabel.text = _data.personel[indexPath.row];
  309.         NSLog(@"personel listesi:%@", cell.textLabel.text);
  310.     }
  311.    
  312.     return cell;
  313. }
  314.  
  315. - (void)tableView:(UITableView *)tableView
  316. didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  317.     [self.view endEditing:YES];
  318.     _selectedRow = indexPath.row;
  319.    
  320.     if (tableView.tag == 1) {
  321.         _textFieldScale.text = self.scales[indexPath.row];
  322.     } else if (tableView.tag == 2){
  323.         _textFieldStatus.text = self.companyStatuses[indexPath.row];
  324.     }
  325. }
  326.  
  327. - (void)tableView:(UITableView*)tableView
  328. accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
  329.  
  330. }
  331.  
  332. - (NSString *)tableView:(UITableView *)tableView
  333. titleForHeaderInSection:(NSInteger)section {
  334.  
  335.     if (tableView.tag == 5) {
  336.         return @"Personel Listesi:";
  337.     }
  338.    
  339.     return @"";
  340. }
  341.  
  342. -(UIView *)tableView:(UITableView *)tableView
  343. viewForHeaderInSection:(NSInteger)section{
  344.     NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
  345.    
  346.     if (sectionTitle == nil) {
  347.         return nil;
  348.     }
  349.    
  350.     UILabel *label = [[UILabel alloc] init];
  351.     label.frame = CGRectMake(20, 8, 320, 20);
  352.     label.backgroundColor = [UIColor clearColor];
  353.     label.textColor = [UIColor whiteColor];
  354.     label.shadowColor = [UIColor grayColor];
  355.     label.shadowOffset = CGSizeMake(-1.0, 1.0);
  356.     label.font = [UIFont boldSystemFontOfSize:16];
  357.     label.text = sectionTitle;
  358.    
  359.     UIView *view = [[UIView alloc] init];
  360.     [view addSubview:label];
  361.    
  362.     return view;
  363. }
  364.  
  365. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement