Files
yinmeng-ios/xplan-ios/Main/Home/View/XPHomeSearchViewController.m
2021-12-02 20:33:57 +08:00

126 lines
3.7 KiB
Objective-C

//
// XPHomeSearchViewController.m
// xplan-ios
//
// Created by 冯硕 on 2021/11/29.
//
#import "XPHomeSearchViewController.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "ThemeColor.h"
#import "XPMacro.h"
///View
#import "XPSearchListTableViewCell.h"
#import "XPHomeSearchNavView.h"
///P
#import "XPHomeSearchPresenter.h"
#import "XPHomeSearchProtocol.h"
@interface XPHomeSearchViewController ()<UITableViewDelegate, UITableViewDataSource, XPHomeSearchNavViewDelegate,XPHomeSearchProtocol>
///搜索
@property (nonatomic,strong) XPHomeSearchNavView *searchView;
///列表
@property (nonatomic,strong) UITableView *tableView;
///数据源
@property (nonatomic,strong) NSArray *datasource;
@end
@implementation XPHomeSearchViewController
- (XPHomeSearchPresenter *)createPresenter {
return [[XPHomeSearchPresenter alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.modalPresentationStyle = UIModalPresentationFullScreen;
[self initSubViews];
[self initSubViewConstraints];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
}
#pragma mark - Private Method
- (void)initSubViews {
[self.view addSubview:self.searchView];
[self.view addSubview:self.tableView];
}
- (void)initSubViewConstraints {
[self.searchView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.mas_equalTo(self.view);
make.height.mas_equalTo(kNavigationHeight);
}];
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.mas_equalTo(self.view);
make.top.mas_equalTo(self.searchView.mas_bottom).offset(10);
}];
}
#pragma mark - UITableViewDelegate And UITableViewDataSource
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 74;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.datasource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
XPSearchListTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPSearchListTableViewCell class])];
if (cell == nil) {
cell = [[XPSearchListTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPSearchListTableViewCell class])];
}
return cell;
}
#pragma mark -XPHomeSearchNavViewDelegate
- (void)xPHomeSearchNavView:(XPHomeSearchNavView *)view didClickSearch:(UIButton *)sender {
[self.presenter searchRoomList:view.searchTextField.text];
}
- (void)xPHomeSearchNavView:(XPHomeSearchNavView *)view didClickBack:(UIButton *)sender {
[view.searchTextField resignFirstResponder];
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark -
- (void)searchRoomSuccess:(NSArray *)data {
self.datasource = data;
[self.tableView reloadData];
}
#pragma mark - Getters And Setters
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.tableFooterView = [UIView new];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.backgroundColor = [UIColor clearColor];
if (@available(iOS 11.0, *)) {
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
[_tableView registerClass:[XPSearchListTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPSearchListTableViewCell class])];
}
return _tableView;
}
- (XPHomeSearchNavView *)searchView {
if (!_searchView) {
_searchView = [[XPHomeSearchNavView alloc] init];
_searchView.delegate = self;
}
return _searchView;
}
@end