Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HMXSelectViewController.h
- #import <UIKit/UIKit.h>
- @interface HMXSelectViewController : UITableViewController
- @property (strong, nonatomic) NSArray *items;
- @property (strong, nonatomic) UITextField *tergetTextField;
- - (void)setItems:(NSArray *)array :(UITextField*)textField;
- - (void)returnToParent;
- @end
- HMXSelectViewController.m
- #import "HMXSelectViewController.h"
- @implementation HMXSelectViewController
- - (id)initWithStyle:(UITableViewStyle)style{
- self = [super initWithStyle:style];
- if (self) {
- }
- return self;
- }
- - (void)viewDidLoad{
- [super viewDidLoad];
- }
- - (void)setItems:(NSArray *)array :(UITextField*)textField{
- self.items = array;
- self.tergetTextField = textField;
- }
- #pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView
- numberOfRowsInSection:(NSInteger)section{
- // Return the number of rows in the section.
- return _items.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView
- cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell =
- [tableView
- dequeueReusableCellWithIdentifier:CellIdentifier
- forIndexPath:indexPath];
- UILabel *label = (UILabel*)[cell viewWithTag:2];
- label.text = _items[indexPath.row];
- return cell;
- }
- - (void)tableView:(UITableView *)tableView
- didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- self.tergetTextField.text = self.items[indexPath.row];
- [self performSelector:@selector(returnToParent) withObject:nil afterDelay:0.5];
- }
- - (void) returnToParent {
- [self.navigationController popViewControllerAnimated:NO];
- }
- @end
- HMXNewCompanyViewController.h
- #import <UIKit/UIKit.h>
- #import "HMXCompanyData.h"
- #import "HMXNewPersonnelData.h"
- static HMXNewPersonnelData *newPersonelData;
- @interface HMXNewCompanyViewController : UIViewController
- @property (strong, nonatomic) IBOutlet UINavigationBar *navigationbar;
- @property (strong, nonatomic) IBOutlet UITextField *textFieldName;
- @property (strong, nonatomic) IBOutlet UITextField *textFieldPhone;
- @property (strong, nonatomic) IBOutlet UITextField *textFieldEmail;
- @property (strong, nonatomic) IBOutlet UITextField *textFieldUrl;
- @property (strong, nonatomic) IBOutlet UITextField *textFieldScale;
- @property (strong, nonatomic) IBOutlet UITextField *textFieldStatus;
- @property (strong, nonatomic) IBOutlet UITextView *textViewAddress;
- @property (strong, nonatomic) IBOutlet UITableView *tableViewPersonel;
- @property (strong, nonatomic) IBOutlet UITableView *tableViewNew;
- @property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
- @property (nonatomic) NSInteger step;
- @property (nonatomic) NSInteger selectedRow;
- @property (retain, nonatomic) HMXCompanyData *data;
- @property (strong, nonatomic) UITextField *activeField;
- @property (nonatomic) CGSize kbSize;
- @property (strong, nonatomic) NSArray *scales;
- @property (strong, nonatomic) NSArray *companyStatuses;
- //- (void)setStep:(NSInteger)step;
- //- (void)setData:(HMXCompanyData *)newdata;
- - (IBAction)backButtonClicked:(id)sender;
- - (IBAction)backgroundTouched:(id)sender;
- - (IBAction)scaleEditingDidBegin:(id)sender;
- - (IBAction)statusEditingDidBegin:(id)sender;
- - (IBAction)nextOneClicked:(id)sender;
- - (IBAction)addPersonelClicked:(id)sender;
- @end
- HMXNewCompanyViewController.m
- #import "HMXNewCompanyViewController.h"
- #import "HMXCompanyData.h"
- #import "HMXNewPersonnelData.h"
- #import "HMXSelectViewController.h"
- #import "HMXAddDeparmentViewController.h"
- int selectionSource;
- @implementation HMXNewCompanyViewController
- - (void)viewDidLoad{
- [super viewDidLoad];
- if([self.title isEqualToString:@"step1"]){
- [self registerForKeyboardNotifications];
- [self.scrollView
- addGestureRecognizer:
- [[UITapGestureRecognizer alloc]
- initWithTarget:self
- action:@selector(handleSingleTap:)]];
- [self.navigationbar
- addGestureRecognizer:
- [[UITapGestureRecognizer alloc]
- initWithTarget:self
- action:@selector(handleSingleTap:)]];
- UIView* dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
- _textFieldScale.inputView = dummyView;
- _textFieldStatus.inputView = dummyView;
- self.textViewAddress.clipsToBounds = YES;
- self.textViewAddress.layer.cornerRadius = 10.0f;
- self.scales = @[@"Mikro", @"Kobi", @"Büyük"];
- self.companyStatuses = @[@"Aktif", @"Pasif"];
- }
- }
- - (void)handleSingleTap:(UITapGestureRecognizer*)sender {
- if (sender.state == UIGestureRecognizerStateEnded){
- [self backgroundTouched:self];
- }
- }
- - (void)registerForKeyboardNotifications {
- [[NSNotificationCenter defaultCenter]
- addObserver:self
- selector:@selector(keyboardDidShow:)
- name:UIKeyboardDidShowNotification object:nil];
- [[NSNotificationCenter defaultCenter]
- addObserver:self
- selector:@selector(keyboardWillHide:)
- name:UIKeyboardWillHideNotification object:nil];
- }
- - (void)keyboardDidShow:(NSNotification*)aNotification {
- NSDictionary* info = [aNotification userInfo];
- _kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
- }
- - (void)keyboardWillHide:(NSNotification*)aNotification {
- UIEdgeInsets contentInsets = UIEdgeInsetsZero;
- _scrollView.contentInset = contentInsets;
- _scrollView.scrollIndicatorInsets = contentInsets;
- }
- - (void)addPersonel:(HMXNewPersonnelData *)personelData{
- if(_data.personel == NULL)
- _data.personel = [[NSMutableArray alloc] init];
- [_data.personel addObject:personelData.nameAndSurname];
- [self.tableViewPersonel reloadData];
- }
- - (IBAction)backButtonClicked:(id)sender {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (IBAction)backgroundTouched:(id)sender {
- [self.view endEditing:YES];
- }
- - (IBAction)scaleEditingDidBegin:(id)sender {
- selectionSource = 0;
- [self performSegueWithIdentifier:@"select" sender:self];
- }
- - (IBAction)statusEditingDidBegin:(id)sender {
- selectionSource = 1;
- [self performSegueWithIdentifier:@"select" sender:self];
- }
- - (IBAction)nextOneClicked:(id)sender {
- if (_textFieldName.text == NULL ||
- _textFieldPhone.text == NULL ||
- _textFieldEmail.text == NULL ||
- _textFieldUrl.text == NULL ||
- _textFieldScale.text == NULL ||
- _textViewAddress.text == NULL ||
- _textFieldStatus.text == NULL) {
- UIAlertView *alert =
- [[UIAlertView alloc]
- initWithTitle:nil
- message:@"Lütfen boş alanları doldurup tekrar deneyin!"
- delegate:self
- cancelButtonTitle:@"Tamam"
- otherButtonTitles:nil, nil];
- [alert show];
- return;
- }
- if(_data == NULL)
- _data = [[HMXCompanyData alloc] init];
- _data.name = _textFieldName.text;
- _data.phone = _textFieldPhone.text;
- _data.email = _textFieldEmail.text;
- _data.url = _textFieldUrl.text;
- _data.scale = _textFieldScale.text;
- _data.address = _textViewAddress.text;
- _data.staus = _textFieldStatus.text;
- [self performSegueWithIdentifier:@"ekle" sender:self];
- }
- - (IBAction)nextTwoClicked:(id)sender {
- _step = 2;
- [self performSegueWithIdentifier:@"ekle" sender:self];
- }
- - (IBAction)addPersonelClicked:(id)sender {
- [self performSegueWithIdentifier:@"addPersonel" sender:self];
- }
- - (void)setData:(HMXCompanyData *)newdata{
- self.data = newdata;
- }
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
- // if ([[segue identifier] isEqualToString:@"ekle"]) {
- // HMXAddDeparmentViewController *vc = [segue destinationViewController];
- // [vc setData:_data];
- // }
- // else
- if ([[segue identifier] isEqualToString:@"select"]){
- HMXSelectViewController *vc = [segue destinationViewController];
- if(selectionSource == 0)
- [vc setItems:self.scales:self.textFieldScale];
- else [vc setItems:self.companyStatuses:self.textFieldStatus];
- }
- }
- #pragma mark - Table view methods
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView
- numberOfRowsInSection:(NSInteger)section{
- if (tableView.tag == 1) {
- return 3;
- } else if (tableView.tag == 2){
- return 2;
- } else if(tableView.tag == 5){
- NSLog(@"personel listesi: boyut :%d", _data.personel.count);
- return _data.personel.count;
- }
- return 0;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView
- cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
- UILabel *label = (UILabel*)[cell viewWithTag:1];
- if (tableView.tag == 1) {
- label.text = self.scales[indexPath.row];
- } else if (tableView.tag == 2){
- label.text = self.companyStatuses[indexPath.row];
- } else if(tableView.tag == 5){
- cell.textLabel.text = _data.personel[indexPath.row];
- NSLog(@"personel listesi:%@", cell.textLabel.text);
- }
- return cell;
- }
- - (void)tableView:(UITableView *)tableView
- didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [self.view endEditing:YES];
- _selectedRow = indexPath.row;
- if (tableView.tag == 1) {
- _textFieldScale.text = self.scales[indexPath.row];
- } else if (tableView.tag == 2){
- _textFieldStatus.text = self.companyStatuses[indexPath.row];
- }
- }
- - (void)tableView:(UITableView*)tableView
- accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
- }
- - (NSString *)tableView:(UITableView *)tableView
- titleForHeaderInSection:(NSInteger)section {
- if (tableView.tag == 5) {
- return @"Personel Listesi:";
- }
- return @"";
- }
- -(UIView *)tableView:(UITableView *)tableView
- viewForHeaderInSection:(NSInteger)section{
- NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
- if (sectionTitle == nil) {
- return nil;
- }
- UILabel *label = [[UILabel alloc] init];
- label.frame = CGRectMake(20, 8, 320, 20);
- label.backgroundColor = [UIColor clearColor];
- label.textColor = [UIColor whiteColor];
- label.shadowColor = [UIColor grayColor];
- label.shadowOffset = CGSizeMake(-1.0, 1.0);
- label.font = [UIFont boldSystemFontOfSize:16];
- label.text = sectionTitle;
- UIView *view = [[UIView alloc] init];
- [view addSubview:label];
- return view;
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement