|
|
@@ -16,8 +16,13 @@
|
|
|
#import "MyAutocompleteView.h"
|
|
|
#import "AMResultViewController.h"
|
|
|
|
|
|
-@interface SearchViewController ()
|
|
|
+@interface SearchViewController () <UISearchBarDelegate>
|
|
|
@property (strong,nonatomic) SearchTableAdapter* adapter ;
|
|
|
+@property (strong, nonatomic) IBOutlet UISearchBar *searchaBar;
|
|
|
+@property (strong, nonatomic) IBOutlet NSLayoutConstraint *tableBottomConstraint;
|
|
|
+@property (nonatomic,assign) BOOL showTable;
|
|
|
+@property (nonatomic,strong) NSIndexPath *editingIndexPath;
|
|
|
+
|
|
|
@end
|
|
|
|
|
|
@implementation SearchViewController
|
|
|
@@ -55,8 +60,53 @@
|
|
|
|
|
|
DebugLog(@"viewDidLoad");
|
|
|
|
|
|
+ self.table.tableFooterView = [UIView new];
|
|
|
+ self.searchaBar.delegate = self;
|
|
|
+}
|
|
|
+
|
|
|
+- (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=[[SearchTableAdapter alloc] init];
|
|
|
+ [self.adapter initfields:self.function_name];
|
|
|
+ } 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];
|
|
|
@@ -180,6 +230,8 @@
|
|
|
// 解决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
|
|
|
//{
|
|
|
@@ -213,8 +265,12 @@
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
|
|
{
|
|
|
|
|
|
+ if (self.showTable) {
|
|
|
+ return [_adapter get_itemcount];
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
|
|
|
- return [_adapter get_itemcount];
|
|
|
}
|
|
|
|
|
|
//- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
|
|
|
@@ -425,7 +481,7 @@
|
|
|
}
|
|
|
}
|
|
|
[params setValue:self.function_name forKey:@"module_name"];
|
|
|
-
|
|
|
+ [params setValue:self.searchaBar.text forKey:@"keyword"];
|
|
|
|
|
|
// GridResultViewController *resultViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ResultViewController"];
|
|
|
// resultViewController.function_name = self.function_name;
|
|
|
@@ -495,18 +551,18 @@
|
|
|
#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];
|
|
|
- }
|
|
|
+// 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];
|
|
|
@@ -519,6 +575,7 @@
|
|
|
DebugLog(@"%s row=%ld type=%@",__func__,(long)[indexPath row], [field valueForKey:@"type"]);
|
|
|
if(![[field valueForKey:@"type"] isEqualToString:@"time"])
|
|
|
{
|
|
|
+ self.editingIndexPath = indexPath;
|
|
|
self.textFieldtmp = textField;
|
|
|
}
|
|
|
}
|
|
|
@@ -545,7 +602,7 @@
|
|
|
{
|
|
|
|
|
|
DebugLog(@"textFieldDidEndEditing%@",textField.text);
|
|
|
-
|
|
|
+ self.editingIndexPath = nil;
|
|
|
UITableViewCell *cell = (UITableViewCell *)[[textField superview] superview];
|
|
|
|
|
|
NSIndexPath *indexPath = [self.table indexPathForCell:cell];
|
|
|
@@ -577,6 +634,7 @@
|
|
|
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;
|
|
|
}
|