| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- //
- // LogCommentVC.m
- // IBOSS
- //
- // Created by Dongke on 15/11/2.
- // Copyright © 2015年 elongtian. All rights reserved.
- //
- #import "LogCommentVC.h"
- #import "LogCommentTableViewCell.h"
- #import "LogShareAndCommentModel.h"
- #import "LogShareAndCommentInfoModel.h"
- #import "CommentDelegate.h"
- @interface LogCommentVC ()<UISearchBarDelegate,UITableViewDataSource,UITableViewDelegate>
- @property(nonatomic,strong) ASIDownManager *mDownManager;
- @property(strong) IBOutlet UISearchBar *searchBar;
- @property(strong) UITableView *tableView;
- @property (nonatomic,assign)DataSearchState searchState;
- @property(nonatomic,strong) LogShareAndCommentModel *model;
- @property(nonatomic,strong) UIBarButtonItem *menuButtonOk;
- @property(nonatomic,strong) UIButton *btnOk;
- @end
- @implementation LogCommentVC
- -(instancetype)init{
- self=[super init];
- if(self){
- self.filterArr=[NSMutableArray new];
- self.searchArr=[NSMutableArray new];
- self.model=[LogShareAndCommentModel new];
- }
-
- return self;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.navigationItem.title=@"请选择";
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button setBackgroundImage:[UIImage imageNamed:@"icon_back.png"]
- forState:UIControlStateNormal];
- [button addTarget:self action:@selector(goBack)
- forControlEvents:UIControlEventTouchUpInside];
- button.frame = CGRectMake(0, 0, 15, 18);
-
- UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
- self.navigationItem.leftBarButtonItem = menuButton;
- self.tableView=[UITableView new];
- self.tableView.dataSource=self;
- self.tableView.delegate=self;
- self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
- self.tableView.frame=CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-44-20) ;
- [self.view addSubview:self.tableView];
-
- //搜索框
- self.searchBar=[[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
- self.searchBar.delegate=self;
- self.tableView.tableHeaderView=self.searchBar;
- }
- /**
- 高度
-
- @return <#return value description#>
- */
- - (NSMutableDictionary *)heights{
- if (_heights == nil){
- _heights = [NSMutableDictionary dictionary];
- }
- return _heights;
- }
- -(void)viewWillAppear:(BOOL)animated{
- if(!_filterArr){
- _filterArr=[NSMutableArray new];
- _searchArr=[NSMutableArray new];
- }
-
- [_searchArr addObjectsFromArray:_filterArr];
- [_model setShareAndCommentArr:_filterArr ];
- [self.tableView reloadData];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- -(void)dealloc{
- [self cancel];
- }
- #pragma mark - Table view data source cell
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- static NSString *CellIdentifier = @"LogCommentTableViewCell";
- LogCommentTableViewCell* cell=(LogCommentTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
-
- cell=[[LogCommentTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
-
- LogShareAndCommentInfoModel* infoModel=self.model.shareCommentArr[indexPath.row];
- infoModel.isChecked=NO;
- [cell parseInfoModel:infoModel];
- cell.delegate=self;
- cell.cellIndex=indexPath.row;
- self.heights[@(indexPath.row)]=@(cell.height);
- return cell;
- }
- #pragma mark -Table view data source number
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return _filterArr.count;
- }
- - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 89.0;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return [self.heights[@(indexPath.row)] doubleValue];
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
-
- [self.commentDelegate reCommentData:self.model.shareCommentArr[indexPath.row]];
-
- [self.navigationController popViewControllerAnimated:YES];
- }
- #pragma 返回
- -(void)goBack
- {
- [self.navigationController popViewControllerAnimated:YES];
- }
- //进度条取消
- - (void)cancel {
- [self stopLoading];
- }
- -(void)addCancelButton
- {
- //添加取消按钮
- UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
- [button2 addTarget:self action:@selector(cancelSearch)
- forControlEvents:UIControlEventTouchUpInside];
- button2.frame = CGRectMake(0, 0, 40, 24);
- [button2 setTitle:@"取消" forState:UIControlStateNormal];
- [button2 setTitleColor:NavBarItemColor forState:UIControlStateNormal];
- UIBarButtonItem *menuButton2 = [[UIBarButtonItem alloc] initWithCustomView:button2];
- self.navigationItem.rightBarButtonItem = menuButton2;
- }
- -(void)cancelSearch
- {
- [_searchBar resignFirstResponder];
- }
- -(void) removeCancel
- {
- self.navigationItem.rightBarButtonItem = nil;
- }
- #pragma mark search bar delegate
- - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
- {
- return YES;
- }
- - (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
- {
- return YES;
- }
- - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
- {
- if ([searchText isEqualToString:@""]) {
- self.filterArr = _searchArr;
- [_model setShareAndCommentArr:_filterArr ];
- [_tableView reloadData];
- return;
- }
- NSString *keyName = @"UserName";
- //< 模糊查找
- NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K CONTAINS[cd] %@", keyName, searchText];
- //< 精确查找
- // NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K == %@", keyName, searchText];
- NSLog(@"predicate %@",predicateString);
- NSMutableArray *filteredArray = [NSMutableArray arrayWithArray:[_searchArr filteredArrayUsingPredicate:predicateString]];
- self.filterArr = filteredArray;
- [_model setShareAndCommentArr:_filterArr ];
- [_tableView reloadData];
- }
- - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
- {
- [searchBar resignFirstResponder];
- [self cancelSearch];
- }
- - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
- {
- [_searchBar resignFirstResponder];
- [self cancelSearch];
- }
- @end
|