| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886 |
- //
- // SearchViewController.m
- // Apex Mobile
- //
- // Created by Ray on 14-3-3.
- // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
- //
-
- #import "const.h"
- #import "SearchViewController.h"
- #import "SearchTableAdapterJson.h"
- //#import "DB_Field.h"
- #import "TableCellEdit.h"
- #import "TableCellDate.h"
- #import "TableCellBool.h"
- #import "MyAutocompleteView.h"
- //#import "AMResultViewController.h"
- #import "ResultViewController.h"
- @interface SearchViewController () <UISearchBarDelegate>
- @property (strong,nonatomic) SearchTableAdapterJson* adapter ;
- @property (strong, nonatomic) IBOutlet UISearchBar *searchaBar;
- @property (strong, nonatomic) IBOutlet NSLayoutConstraint *tableBottomConstraint;
- @property (nonatomic,assign) BOOL showTable;
- @property (nonatomic,strong) NSIndexPath *editingIndexPath;
- @property (strong, nonatomic) IBOutlet NSLayoutConstraint *toolBarheightConstraint;
- @property (strong, nonatomic) IBOutlet UIToolbar *searchToolbar;
- @end
- @implementation SearchViewController
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- self.ioffset = 0;
- NSString* title=@"";
- if([self.subtype isEqualToString:@"aci"])
- title = @"ACI Search";
- else if([self.subtype isEqualToString:@"isf"])
- title = @"ISF Search";
- else if([self.subtype isEqualToString:@"acem1"])
- title = @"ACE-M1 Search";
- else if([self.subtype isEqualToString:@"emanifest"])
- title = @"eManifest Search";
- else if([self.subtype isEqualToString:@"customer"])
- title = @"Customer Search";
- self.navigationItem.title = title;
-
-
- // UIBarButtonItem *backButton = [[UIBarButtonItem alloc] init];
- // backButton.title = @"Back";
- // self.navigationItem.backBarButtonItem = backButton;
-
- self.dirty = true;
-
- DebugLog(@"viewDidLoad");
-
- self.table.tableFooterView = [UIView new];
- self.searchaBar.delegate = self;
-
- // 2019.1.8 使得Document显示searchToolbar
- // if ([self.function_name isEqualToString:@"Download Document"]) {
- // self.toolBarheightConstraint.constant = 0;
- // [self.view layoutIfNeeded];
- // self.searchToolbar.hidden = YES;
- // self.showTable = YES;
- // }
-
- // UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
- // backItem.title = @"";
- // self.navigationItem.backBarButtonItem = backItem;
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
-
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (void)keyboardWillChangeFrame:(NSNotification *)notification {
-
- // NSTimeInterval duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
- // CGRect begin = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
- CGRect end = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
-
- CGFloat endY = CGRectGetMinY(end);
- CGFloat screenHeight = CGRectGetHeight([UIScreen mainScreen].bounds);
- CGFloat offset = screenHeight - endY;
- CGFloat tableHeightoffset = offset - 44;
- if (tableHeightoffset > 0) {
- self.tableBottomConstraint.constant = offset;
- if (self.editingIndexPath) {
- [self.table scrollToRowAtIndexPath:self.editingIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];
- }
- } else {
- self.tableBottomConstraint.constant = offset;
- }
- [self.view layoutIfNeeded];
- }
- - (IBAction)searchTableExpandableBtnClick:(UIButton *)sender {
- sender.selected = !sender.selected;
- self.showTable = !self.showTable;
- if (self.showTable) {
- self.adapter=[[SearchTableAdapterJson alloc] init];
- [self.adapter initfields:@"search" subtype:self.subtype];
- } else {
- self.adapter = nil;
- }
- [self.table reloadData];
- }
- - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
- [self SearchBtnOnClick:nil];
- }
- - (IBAction)onBoolitemClick:(UIButton *)sender {
- DebugLog(@"onBoolitemClick");
- UITableViewCell *cell = (UITableViewCell *)[[sender superview] superview];
- // DebugLog(@"reuseid:%@",cell.reuseIdentifier);
- // // UITableViewCell *cell = (UITableViewCell *)[[textField superview] superview];
-
- NSIndexPath *indexPath = [self.table indexPathForCell:cell];
- if(indexPath==nil)
- {//for ios7
- cell = (UITableViewCell *) sender.superview.superview.superview;
- indexPath = [self.table indexPathForCell:cell];
- }
- // NSMutableDictionary * field =[_adapter get_item:[indexPath row]];
- // DebugLog(@"textFieldShouldBeginEditing row=%ld type=%@",(long)[indexPath row], [field valueForKey:@"type"]);
- // if(![[field valueForKey:@"type"] isEqualToString:@"bool"])
- // return YES;
-
- NSString *title = NSLocalizedString(@"select_val", nil);//UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation) ? @"Select value" : @"Select value";
- // UIActionSheet *selBool = [[UIActionSheet alloc] initWithTitle:title
- // delegate:self
- // cancelButtonTitle:NSLocalizedString(@"no", nil)
- // destructiveButtonTitle:NSLocalizedString(@"clear", nil)
- // otherButtonTitles:NSLocalizedString(@"yes", nil),
- // nil];
- // selBool.tag = 1;
- // //dateDialog.actionSheetStyle = self.navigationController.navigationBar.barStyle;
- // [selBool showInView:self.view];
- self.boolBtntmp = sender;
-
- // UIDatePicker *datePicker = [[UIDatePicker alloc] init];
- // datePicker.tag = 101;
- // datePicker.datePickerMode=UIDatePickerModeDate;
- // [dateDialog addSubview:datePicker];
-
-
- // NSIndexPath *indexPath = [self.table indexPathForCell:cell];
- // 此处编写弹出日期选择器的代码。
- // self.textFieldtmp=textField;
-
- __weak typeof(self) weakSelf = self;
- UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleActionSheet];
- UIAlertAction *noAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"no", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- TableCellBool *cell = (TableCellBool *)[[weakSelf.boolBtntmp superview] superview];
-
- NSIndexPath *indexPath = [weakSelf.table indexPathForCell:cell];
- if(indexPath==nil)
- {//for ios7
- cell = (TableCellBool *) weakSelf.boolBtntmp.superview.superview.superview;
- indexPath = [weakSelf.table indexPathForCell:cell];
- }
-
- {
- [weakSelf.boolBtntmp setTitle:@"No" forState:UIControlStateNormal];
- NSMutableDictionary* item =[weakSelf.adapter get_item:[indexPath row]];
- [item setValue:@"false" forKey:@"value"];
- [weakSelf.adapter set_item:indexPath.row item:item];
- }
-
-
- }];
-
- UIAlertAction *clearAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"clear", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
-
- TableCellBool *cell = (TableCellBool *)[[weakSelf.boolBtntmp superview] superview];
-
- NSIndexPath *indexPath = [weakSelf.table indexPathForCell:cell];
- if(indexPath==nil)
- {//for ios7
- cell = (TableCellBool *) weakSelf.boolBtntmp.superview.superview.superview;
- indexPath = [weakSelf.table indexPathForCell:cell];
- }
-
-
- {
- [self.boolBtntmp setTitle:@"Not set" forState:UIControlStateNormal];
- NSMutableDictionary* item =[weakSelf.adapter get_item:[indexPath row]];
- [item setValue:@"" forKey:@"value"];
- [weakSelf.adapter set_item:indexPath.row item:item];
-
- }
-
-
- }];
-
- UIAlertAction *yesAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"yes", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- TableCellBool *cell = (TableCellBool *)[[weakSelf.boolBtntmp superview] superview];
-
- NSIndexPath *indexPath = [weakSelf.table indexPathForCell:cell];
- if(indexPath==nil)
- {//for ios7
- cell = (TableCellBool *) weakSelf.boolBtntmp.superview.superview.superview;
- indexPath = [weakSelf.table indexPathForCell:cell];
- }
-
- {
- [weakSelf.boolBtntmp setTitle:@"Yes" forState:UIControlStateNormal];
- NSMutableDictionary* item =[weakSelf.adapter get_item:[indexPath row]];
- [item setValue:@"true" forKey:@"value"];
- [weakSelf.adapter set_item:indexPath.row item:item];
- }
-
- }];
- [alertVC addAction:yesAction];
- [alertVC addAction:noAction];
- [alertVC addAction:clearAction];
-
- [self presentViewController:alertVC animated:YES completion:nil];
-
-
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- DebugLog(@"viewWillAppear");
- if(self.dirty ==true)
- {
- _adapter=[[SearchTableAdapterJson alloc] init];
- [self.adapter initfields:@"search" subtype:self.subtype];
-
- [self.table reloadData];
- self.dirty=false;
- }
- [self.table reloadData];
-
- // 解决Items按钮灰色
- self.navigationItem.rightBarButtonItem.enabled = false;
- self.navigationItem.rightBarButtonItem.enabled = true;
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
- }
- //-(void) viewWillDisappear:(BOOL)animated
- //{
- // [[self view] endEditing:animated];
- //}
- - (IBAction)onCustomize:(UIBarButtonItem *)sender {
-
- CustomizeFieldViewController *ViewController = [[UIStoryboard storyboardWithName:@"Fields" bundle:nil] instantiateViewControllerWithIdentifier:@"CustomizeFieldViewController"];
- // ViewController.function_name = self.function_name;
- ViewController.type = @"search";
- ViewController.subtype = self.subtype;
- ViewController.behavior =BEHAVIOR_SEARCH;
- self.dirty = true;
- //ViewController.dirty = self.dirty;
- // ViewController.
-
- [self.navigationController pushViewController:ViewController animated:YES];
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- #pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- DebugLog(@"numberOfSectionsInTableView");
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
-
- if (self.showTable) {
- return [_adapter get_itemcount];
- } else {
- return 0;
- }
-
- }
- //- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
- //
- //}
- //- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath
- //{
- // [[self view] endEditing:YES];
- // return false;
- //}
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- NSMutableDictionary * field =[_adapter get_item:[indexPath row]];
-
-
- if([[field valueForKey:@"type"] isEqualToString:@"boolean"])
- {
- NSString *CellIdentifier = @"item_bool";
- TableCellBool *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- cell.anameLabel.text = [field valueForKey:@"aname"];
- NSString * val = [field valueForKey:@"value"];
- if(val.length==0)
- [cell.valButton setTitle:@"Not set" forState:UIControlStateNormal];
- else
- if([val isEqualToString:@"true"])
- [cell.valButton setTitle:@"Yes" forState:UIControlStateNormal];
- else
- [cell.valButton setTitle:@"No" forState:UIControlStateNormal];
- [cell.anameLabel sizeToFit];
- DebugLog(@"cellForRowAtIndexPath%@",[field valueForKey:@"aname"]);
-
- // Configure the cell...
-
- return cell;
-
-
-
- }
- else if([[field valueForKey:@"type"] isEqualToString:@"time"])
- {
- NSString *CellIdentifier = @"item_date";
- TableCellDate *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- cell.anameLabel.text = [field valueForKey:@"aname"];
- [cell.anameLabel sizeToFit];
- DebugLog(@"cellForRowAtIndexPath%@",[field valueForKey:@"aname"]);
-
- // Configure the cell...
- NSString* str_from= [field valueForKey:@"from"];
- NSString* str_to= [field valueForKey:@"to"];
- // if(str_from.length>0)
- cell.fromEdit.text = str_from;
- cell.toEdit.text = str_to;
- return cell;
-
- // static NSString *CellIdentifier = @"item_date";
- ////
- //// //注册要使用的cell
- //// [tableView registerClass:[TableCellDate class]
- //// forCellReuseIdentifier:CellIdentifier];
- //
- // //创建cell
- // TableCellDate *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- //
- // if(cell == nil)
- // {
- // cell = [[TableCellDate alloc] initWithStyle:UITableViewCellStyleValue1
- // reuseIdentifier:CellIdentifier];
- // }
- //
- // cell.anameLabel.text = [field valueForKey:@"aname"];
- // [cell.anameLabel sizeToFit];
- // DebugLog(@"cellForRowAtIndexPath%@",[field valueForKey:@"aname"]);
- // return cell;
- }
- else
- {
- NSString *CellIdentifier = @"item_edit";
- NSString * type = [field valueForKey:@"type"];
-
-
- TableCellEdit *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- cell.anameLabel.text = [field valueForKey:@"aname"];
- [cell.anameLabel sizeToFit];
- NSString * val = [field valueForKey:@"value"];
- if([type isEqualToString:@"int"])
- cell.valueEdit.keyboardType = UIKeyboardTypeNumberPad;
- else
- cell.valueEdit.keyboardType = UIKeyboardTypeDefault;
- cell.valueEdit.text = val;
- NSArray* array=nil;
- // NSArray* array = [ApexMobileDB get_searchhistory:[field valueForKey:@"name"]];
- // [self.autocompleteView.itemsSource put_predictions:array ];
-
- MyAutocompleteView* autocompleteView = [MyAutocompleteView autocompleteViewBindedTo:cell.valueEdit
- usingSource:[[MyAutocompleteItemsSource alloc]
- initWithMinimumCharactersToTrigger:1
- source:array
- ]
- cellFactory:[[MyAutocompletionCellFactory alloc]
- initWithCellTextColor:[UIColor blackColor]
- fontSize:14]
- // presentingIn:self
- parentView:self.table];
- autocompleteView.topMargin = 0;
- // self.autocompleteView.backgroundColor = [UIColor ui];
-
- autocompleteView.didAutocompleteWith = ^(MySuggestion* item)
- {
- NSLog(@"Autocompleted with: %@", item.completionText);
- };
- cell.autocompleteView = autocompleteView;
- // if(val.length==0)
- DebugLog(@"cellForRowAtIndexPath%@",[field valueForKey:@"aname"]);
- // Configure the cell...
-
- return cell;
-
- // static NSString *CellIdentifier = @"item_edit";
- //
- //// //注册要使用的cell
- //// [tableView registerClass:[TableCellEdit class]
- //// forCellReuseIdentifier:CellIdentifier];
- //
- // //创建cell
- // TableCellEdit *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- //
- // if(cell == nil)
- // {
- // cell = [[TableCellEdit alloc] initWithStyle:UITableViewCellStyleValue1
- // reuseIdentifier:CellIdentifier];
- // }
- //
- // cell.anameLabel.text = [field valueForKey:@"aname"];
- // [cell.anameLabel sizeToFit];
- // DebugLog(@"cellForRowAtIndexPath%@",[field valueForKey:@"aname"]);
- // return cell;
-
- }
- return nil;
-
-
- }
- - (IBAction)ClearBtnOnClick:(UIButton *)sender {
- UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"attention", nil) message:NSLocalizedString(@"alert_title_confirm_clear", nil) preferredStyle:UIAlertControllerStyleAlert];
-
- __weak typeof(self) weakSelf = self;
- UIAlertAction *noAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"no", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- }];
-
- UIAlertAction *yesAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"yes", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- [weakSelf.view endEditing:YES];
- weakSelf.adapter=[[SearchTableAdapterJson alloc] init];
- [weakSelf.adapter initfields:@"search" subtype:weakSelf.subtype];
- [weakSelf.table reloadData];
-
- }];
-
- [alertVC addAction:noAction];
- [alertVC addAction:yesAction];
-
- [self presentViewController:alertVC animated:YES completion:nil];
- }
- - (IBAction)SearchBtnOnClick:(UIButton *)sender {
-
- [self.textFieldtmp endEditing:true];
- // if([self.function_name isEqualToString:@"Document Download"])
- // resultViewController.fullrow_select =false;
- // else
- // resultViewController.fullrow_select=true;
- NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
- for(int i=0;i<[_adapter get_itemcount];i++)
- {
- NSMutableDictionary * field =[_adapter get_item:i];
- if([[field valueForKey:@"type"] isEqualToString:@"time"])
- {
- NSString* str_from= [field valueForKey:@"from"];
- NSString* str_to= [field valueForKey:@"to"];
- if(str_from.length>0)
- [params setValue:str_from forKey:[NSString stringWithFormat:@"%@_from",[field valueForKey:@"name"]]];
- if(str_to.length>0)
- [params setValue:str_to forKey:[NSString stringWithFormat:@"%@_to",[field valueForKey:@"name"]]];
- }
- else
- {
- NSString* value =[field valueForKey:@"value"];
- if(value.length>0)
- {
- [params setValue:[field valueForKey:@"value"] forKey:[field valueForKey:@"name"]];
- if([[field valueForKey:@"type"] isEqualToString:@"string"] )
- {
- // [ApexMobileDB savehistory:[field valueForKey:@"name"] value:[field valueForKey:@"value"]];
- }
- }
- }
- }
- // [params setValue:self.function_name forKey:@"module_name"];
- [params setValue:self.searchaBar.text forKey:@"keyword"];
-
- params[@"sub_type"]=self.subtype;
- // after 2019.1.5
- ResultViewController *vc = [ResultViewController resultViewController:params];
- [self.navigationController pushViewController:vc animated:YES];
-
- // before 2019.1.5
- // AMResultViewController *resultVC = [[AMResultViewController alloc] initWithNibName:@"Result" bundle:nil];
- // resultVC.params = params;
- // [self.navigationController pushViewController:resultVC animated:YES];
-
- // AMResultViewController *resultVC = [[AMResultViewController alloc] initWithNibName:@"Result" bundle:nil];
- // [self.navigationController pushViewController:resultVC animated:YES];
- }
- //- (IBAction)onTouchDown:(UITextField *)sender {
- // DebugLog(@"onTouchDown");
- //}
- //
- //- (IBAction)dateEditOnClick:(UITextField *)sender forEvent:(UIEvent *)event {
- // DebugLog(@"dateEditOnClick");
- // UITableViewCell *cell = (UITableViewCell *)[[sender superview] superview];
- // // DebugLog(@"reuseid:%@",cell.reuseIdentifier);
- // // // UITableViewCell *cell = (UITableViewCell *)[[textField superview] superview];
- // NSIndexPath *indexPath = [self.table indexPathForCell:cell];
- // NSMutableDictionary * field =[_adapter get_item:[indexPath row]];
- // if(![[field valueForKey:@"type"] isEqualToString:@"time"])
- // return ;
- //
- // NSString *title = UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation) ? @"\n\n\n\n\n\n\n\n\n" : @"\n\n\n\n\n\n\n\n\n\n\n\n";
- // UIActionSheet *dateDialog = [[UIActionSheet alloc] initWithTitle:title
- // delegate:self
- // cancelButtonTitle:@"Cancel"
- // destructiveButtonTitle:@"Set"
- // otherButtonTitles:nil,
- // nil];
- // //dateDialog.actionSheetStyle = self.navigationController.navigationBar.barStyle;
- // [dateDialog showInView:self.view];
- // UIDatePicker *datePicker = [[UIDatePicker alloc] init];
- // datePicker.tag = 101;
- // datePicker.datePickerMode=UIDatePickerModeDate;
- // [dateDialog addSubview:datePicker];
- //
- //
- // // NSIndexPath *indexPath = [self.table indexPathForCell:cell];
- // // 此处编写弹出日期选择器的代码。
- // self.textFieldtmp=sender;
- //
- //}
- - (BOOL)shouldAutorotate
- {
- return YES;
- }
- - (UIInterfaceOrientationMask)supportedInterfaceOrientations
- {
- return UIInterfaceOrientationMaskPortrait;
- }
- - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
- {
- return UIInterfaceOrientationPortrait;
- }
- #pragma mark - Text field delegate
- - (void)textFieldDidBeginEditing:(UITextField *)textField {
- // int fieldpos = [textField convertPoint:textField.bounds.origin toView:self.view].y+textField.frame.size.height;
- // fieldpos+=150 ;//autocomplete height;
- // int screenheight =self.view.frame.size.height;
- // int ioffset = fieldpos - (screenheight - 216);//216 -(self.view.frame.size.height-fieldpos);
- // if(ioffset>0)
- // {
- // self.ioffset = ioffset;
- // CGPoint offset = self.table.contentOffset;
- // offset.y+=ioffset;
- // DebugLog(@"table content offset%d",ioffset);
- // [self.table setContentOffset:offset animated:YES];
- // }
-
- UITableViewCell *cell = (UITableViewCell *)[[textField superview] superview];
- NSIndexPath *indexPath = [self.table indexPathForCell:cell];
- if(indexPath==nil)
- {//for ios7
- cell = (UITableViewCell *) textField.superview.superview.superview;
- indexPath = [self.table indexPathForCell:cell];
- }
- NSMutableDictionary * field =[_adapter get_item:[indexPath row]];
- DebugLog(@"%s row=%ld type=%@",__func__,(long)[indexPath row], [field valueForKey:@"type"]);
- if(![[field valueForKey:@"type"] isEqualToString:@"time"])
- {
- self.editingIndexPath = indexPath;
- self.textFieldtmp = textField;
- }
- }
- //- (BOOL)textFieldShouldReturn:(UITextField *)sender {
- // [self.table setContentOffset:CGPointMake(0, 0) animated:YES];
- // return YES;
- //}
- -(BOOL)textFieldShouldReturn:(UITextField *)textField {
-
- // if(self.ioffset>0)
- // {
- //
- // CGPoint offset = self.table.contentOffset;
- // offset.y-=self.ioffset;
- // [self.table setContentOffset:offset animated:YES];
- // self.ioffset = 0;
- // }
- //
- // [self.table setContentOffset:CGPointMake(0, 0) animated:YES];
- [textField resignFirstResponder];
- return YES;
- }
- - (void)textFieldDidEndEditing:(UITextField *)textField
- {
-
- DebugLog(@"textFieldDidEndEditing%@",textField.text);
- self.editingIndexPath = nil;
- UITableViewCell *cell = (UITableViewCell *)[[textField superview] superview];
-
- NSIndexPath *indexPath = [self.table indexPathForCell:cell];
- // if(indexPath==nil)
- // {//for ios7
- // cell = (UITableViewCell *) textField.superview.superview.superview;
- // indexPath = [self.table indexPathForCell:cell];
- // }
- // [self.table setContentOffset:CGPointMake(0, 0) animated:YES];
- NSMutableDictionary* item = [_adapter get_item:[indexPath row]];
- [item setValue:textField.text forKey:@"value"];
-
- [_adapter set_item:[indexPath row] item:item];
-
- self.textFieldtmp = nil;
- }
- //
- - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
- {
- // [self.table setContentOffset:CGPointMake(0, 70) animated:YES];
- DebugLog(@"textFieldShouldBeginEditing text=%@",textField.text);
- UITableViewCell *cell = (UITableViewCell *)[[textField superview] superview];
- // DebugLog(@"reuseid:%@",cell.reuseIdentifier);
- // // UITableViewCell *cell = (UITableViewCell *)[[textField superview] superview];
-
- NSIndexPath *indexPath = [self.table indexPathForCell:cell];
- if(indexPath==nil)
- {//for ios7
- cell = (UITableViewCell *) textField.superview.superview.superview;
- indexPath = [self.table indexPathForCell:cell];
- }
- NSMutableDictionary * field =[_adapter get_item:[indexPath row]];
- DebugLog(@"textFieldShouldBeginEditing row=%ld type=%@",(long)[indexPath row], [field valueForKey:@"type"]);
- if(![[field valueForKey:@"type"] isEqualToString:@"time"])
- {
- self.editingIndexPath = indexPath;
- self.textFieldtmp = textField;
- return YES;
- }
- UIDatePicker *datePicker = [[UIDatePicker alloc] init];
- datePicker.tag = 101;
- datePicker.datePickerMode=UIDatePickerModeDate;
-
- NSString *title = UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation) ? @"\n\n\n\n\n\n\n\n\n" : @"\n\n\n\n\n\n\n\n\n\n\n\n";
- // UIActionSheet *dateDialog = [[UIActionSheet alloc] initWithTitle:title
- // delegate:self
- // cancelButtonTitle:NSLocalizedString(@"cancel",nil)
- // destructiveButtonTitle:NSLocalizedString(@"clear",nil)
- // otherButtonTitles:NSLocalizedString(@"set",nil),
- // nil];
- // dateDialog.tag = 0;
- // //dateDialog.actionSheetStyle = self.navigationController.navigationBar.barStyle;
- // [dateDialog showInView:self.view];
- // [dateDialog addSubview:datePicker];
-
- __weak typeof(self) weakSelf = self;
- UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleActionSheet];
- UIAlertAction *setAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"set",nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- NSDate *date = [datePicker date];
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- //设定时间格式,这里可以设置成自己需要的格式
- [dateFormatter setDateFormat:@"MM/dd/yyyy"];
- //用[NSDate date]可以获取系统当前时间
- self.textFieldtmp.text = [dateFormatter stringFromDate:date];
- UITableViewCell *cell = (UITableViewCell *)[[weakSelf.textFieldtmp superview] superview];
-
- NSIndexPath *indexPath = [weakSelf.table indexPathForCell:cell];
- if(indexPath==nil)
- {//for ios7
- cell = (UITableViewCell *) weakSelf.textFieldtmp.superview.superview.superview;
- indexPath = [weakSelf.table indexPathForCell:cell];
- }
-
- if([weakSelf.textFieldtmp.restorationIdentifier isEqualToString:@"edit_from"])
- {
- NSMutableDictionary* item = [weakSelf.adapter get_item:[indexPath row]];
-
- [item setValue:[dateFormatter stringFromDate:date] forKey:@"from"];
- [weakSelf.adapter set_item:indexPath.row item:item];
- }
- else
- {
- NSMutableDictionary* item = [weakSelf.adapter get_item:[indexPath row]];
-
- [item setValue:[dateFormatter stringFromDate:date] forKey:@"to"];
- [weakSelf.adapter set_item:indexPath.row item:item];
- }
-
- }];
- UIAlertAction *clearAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"clear",nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- weakSelf.textFieldtmp.text=nil;
- UITableViewCell *cell = (UITableViewCell *)[[weakSelf.textFieldtmp superview] superview];
-
- NSIndexPath *indexPath = [weakSelf.table indexPathForCell:cell];
- if(indexPath==nil)
- {//for ios7
- cell = (UITableViewCell *) weakSelf.textFieldtmp.superview.superview.superview;
- indexPath = [weakSelf.table indexPathForCell:cell];
- }
-
- if([weakSelf.textFieldtmp.restorationIdentifier isEqualToString:@"edit_from"])
- {
- NSMutableDictionary* item = [weakSelf.adapter get_item:[indexPath row]];
-
- [item setValue:@"" forKey:@"from"];
- [weakSelf.adapter set_item:indexPath.row item:item];
- }
- else
- {
- NSMutableDictionary* item = [weakSelf.adapter get_item:[indexPath row]];
-
- [item setValue:@"" forKey:@"to"];
- [weakSelf.adapter set_item:indexPath.row item:item];
- }
- }];
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"cancel",nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- [alertVC.view addSubview:datePicker];
- [alertVC addAction:setAction];
- [alertVC addAction:clearAction];
- [alertVC addAction:cancelAction];
- [self presentViewController:alertVC animated:YES completion:nil];
-
- // NSIndexPath *indexPath = [self.table indexPathForCell:cell];
- // 此处编写弹出日期选择器的代码。
- self.textFieldtmp=textField;
- //
- //
- // [UIView setAnimationDuration:5.0];
- // [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- // [UIView commitAnimations];
- //
-
- return NO;
- }
- //- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
- //
- // if(actionSheet.tag==0)
- // {
- //
- // if(buttonIndex==actionSheet.cancelButtonIndex)
- // return;
- // if(buttonIndex==actionSheet.destructiveButtonIndex)
- // {
- // self.textFieldtmp.text=nil;
- // UITableViewCell *cell = (UITableViewCell *)[[self.textFieldtmp superview] superview];
- //
- // NSIndexPath *indexPath = [self.table indexPathForCell:cell];
- // if(indexPath==nil)
- // {//for ios7
- // cell = (UITableViewCell *) self.textFieldtmp.superview.superview.superview;
- // indexPath = [self.table indexPathForCell:cell];
- // }
- //
- // if([self.textFieldtmp.restorationIdentifier isEqualToString:@"edit_from"])
- // [[_adapter get_item:[indexPath row]] setValue:@"" forKey:@"from"];
- // else
- // [[_adapter get_item:[indexPath row]] setValue:@"" forKey:@"to"];
- //
- // }
- // else
- // {
- // UIDatePicker *datePicker = (UIDatePicker *)[actionSheet viewWithTag:101];
- // NSDate *date = [datePicker date];
- // NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- // //设定时间格式,这里可以设置成自己需要的格式
- // [dateFormatter setDateFormat:@"MM/dd/yyyy"];
- // //用[NSDate date]可以获取系统当前时间
- // self.textFieldtmp.text = [dateFormatter stringFromDate:date];
- //
- //
- //
- //
- // // DebugLog(@"textFieldShouldBeginEditing text=%@",textField.text);
- // UITableViewCell *cell = (UITableViewCell *)[[self.textFieldtmp superview] superview];
- // // DebugLog(@"reuseid:%@",cell.reuseIdentifier);
- // // // UITableViewCell *cell = (UITableViewCell *)[[textField superview] superview];
- //
- // NSIndexPath *indexPath = [self.table indexPathForCell:cell];
- // if(indexPath==nil)
- // {//for ios7
- // cell = (UITableViewCell *) self.textFieldtmp.superview.superview.superview;
- // indexPath = [self.table indexPathForCell:cell];
- // }
- // // NSMutableDictionary * field =[_adapter get_item:[indexPath row]];
- //
- // if([self.textFieldtmp.restorationIdentifier isEqualToString:@"edit_from"])
- // [[_adapter get_item:[indexPath row]] setValue:[dateFormatter stringFromDate:date] forKey:@"from"];
- // else
- // [[_adapter get_item:[indexPath row]] setValue:[dateFormatter stringFromDate:date] forKey:@"to"];
- // // DebugLog(@"textFieldShouldBeginEditing row=%ld type=%@",(long)[indexPath row], [field valueForKey:@"type"]);
- // // if(![[field valueForKey:@"type"] isEqualToString:@"time"])
- //
- //
- //
- // }
- // }
- // else
- // {
- // // self.boolBtntmp = sender;
- // TableCellBool *cell = (TableCellBool *)[[self.boolBtntmp superview] superview];
- //
- // NSIndexPath *indexPath = [self.table indexPathForCell:cell];
- // if(indexPath==nil)
- // {//for ios7
- // cell = (TableCellBool *) self.boolBtntmp.superview.superview.superview;
- // indexPath = [self.table indexPathForCell:cell];
- // }
- //
- // if(buttonIndex==actionSheet.cancelButtonIndex)
- // {
- // [self.boolBtntmp setTitle:@"No" forState:UIControlStateNormal];
- // [[_adapter get_item:[indexPath row]] setValue:@"false" forKey:@"value"];
- // }
- // else if(buttonIndex==actionSheet.destructiveButtonIndex)
- // {
- // [self.boolBtntmp setTitle:@"Not set" forState:UIControlStateNormal];
- // [[_adapter get_item:[indexPath row]] setValue:@"" forKey:@"value"];
- // }
- // else
- // {
- // [self.boolBtntmp setTitle:@"Yes" forState:UIControlStateNormal];
- //
- //// cell.anameLabel.text =@"aaa";
- // // [self.boolBtntmp.titleLabel setText:@"yes"];
- // // self.boolBtntmp.titleLabel.text = @"Yes";
- // [[_adapter get_item:[indexPath row]] setValue:@"true" forKey:@"value"];
- // }
- //
- // }
- // // TODO:
- //}
- //-(void)changedDate:(id)sender{
- //
- // //实例化一个NSDateFormatter对象
- // NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- // //设定时间格式,这里可以设置成自己需要的格式
- // [dateFormatter setDateFormat:@"yyyy年MM月dd日"];
- // //用[NSDate date]可以获取系统当前时间
- // self.textFieldtmp.text = [dateFormatter stringFromDate:self.datePicker.date];
- //
- //// [dateFormatter release];
- //
- //}
- @end
|