LogCommentVC.m 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //
  2. // LogCommentVC.m
  3. // IBOSS
  4. //
  5. // Created by Dongke on 15/11/2.
  6. // Copyright © 2015年 elongtian. All rights reserved.
  7. //
  8. #import "LogCommentVC.h"
  9. #import "LogCommentTableViewCell.h"
  10. #import "LogShareAndCommentModel.h"
  11. #import "LogShareAndCommentInfoModel.h"
  12. #import "CommentDelegate.h"
  13. @interface LogCommentVC ()<UISearchBarDelegate,UITableViewDataSource,UITableViewDelegate>
  14. @property(nonatomic,strong) ASIDownManager *mDownManager;
  15. @property(strong) IBOutlet UISearchBar *searchBar;
  16. @property(strong) UITableView *tableView;
  17. @property (nonatomic,assign)DataSearchState searchState;
  18. @property(nonatomic,strong) LogShareAndCommentModel *model;
  19. @property(nonatomic,strong) UIBarButtonItem *menuButtonOk;
  20. @property(nonatomic,strong) UIButton *btnOk;
  21. @end
  22. @implementation LogCommentVC
  23. -(instancetype)init{
  24. self=[super init];
  25. if(self){
  26. self.filterArr=[NSMutableArray new];
  27. self.searchArr=[NSMutableArray new];
  28. self.model=[LogShareAndCommentModel new];
  29. }
  30. return self;
  31. }
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. self.navigationItem.title=@"请选择";
  35. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  36. [button setBackgroundImage:[UIImage imageNamed:@"icon_back.png"]
  37. forState:UIControlStateNormal];
  38. [button addTarget:self action:@selector(goBack)
  39. forControlEvents:UIControlEventTouchUpInside];
  40. button.frame = CGRectMake(0, 0, 15, 18);
  41. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  42. self.navigationItem.leftBarButtonItem = menuButton;
  43. self.tableView=[UITableView new];
  44. self.tableView.dataSource=self;
  45. self.tableView.delegate=self;
  46. self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
  47. self.tableView.frame=CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-44-20) ;
  48. [self.view addSubview:self.tableView];
  49. //搜索框
  50. self.searchBar=[[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
  51. self.searchBar.delegate=self;
  52. self.tableView.tableHeaderView=self.searchBar;
  53. }
  54. /**
  55. 高度
  56. @return <#return value description#>
  57. */
  58. - (NSMutableDictionary *)heights{
  59. if (_heights == nil){
  60. _heights = [NSMutableDictionary dictionary];
  61. }
  62. return _heights;
  63. }
  64. -(void)viewWillAppear:(BOOL)animated{
  65. if(!_filterArr){
  66. _filterArr=[NSMutableArray new];
  67. _searchArr=[NSMutableArray new];
  68. }
  69. [_searchArr addObjectsFromArray:_filterArr];
  70. [_model setShareAndCommentArr:_filterArr ];
  71. [self.tableView reloadData];
  72. }
  73. - (void)didReceiveMemoryWarning {
  74. [super didReceiveMemoryWarning];
  75. }
  76. -(void)dealloc{
  77. [self cancel];
  78. }
  79. #pragma mark - Table view data source cell
  80. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  81. static NSString *CellIdentifier = @"LogCommentTableViewCell";
  82. LogCommentTableViewCell* cell=(LogCommentTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  83. cell=[[LogCommentTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  84. LogShareAndCommentInfoModel* infoModel=self.model.shareCommentArr[indexPath.row];
  85. infoModel.isChecked=NO;
  86. [cell parseInfoModel:infoModel];
  87. cell.delegate=self;
  88. cell.cellIndex=indexPath.row;
  89. self.heights[@(indexPath.row)]=@(cell.height);
  90. return cell;
  91. }
  92. #pragma mark -Table view data source number
  93. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  94. return _filterArr.count;
  95. }
  96. - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
  97. return 89.0;
  98. }
  99. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  100. return [self.heights[@(indexPath.row)] doubleValue];
  101. }
  102. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  103. [self.commentDelegate reCommentData:self.model.shareCommentArr[indexPath.row]];
  104. [self.navigationController popViewControllerAnimated:YES];
  105. }
  106. #pragma 返回
  107. -(void)goBack
  108. {
  109. [self.navigationController popViewControllerAnimated:YES];
  110. }
  111. //进度条取消
  112. - (void)cancel {
  113. [self stopLoading];
  114. }
  115. -(void)addCancelButton
  116. {
  117. //添加取消按钮
  118. UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
  119. [button2 addTarget:self action:@selector(cancelSearch)
  120. forControlEvents:UIControlEventTouchUpInside];
  121. button2.frame = CGRectMake(0, 0, 40, 24);
  122. [button2 setTitle:@"取消" forState:UIControlStateNormal];
  123. [button2 setTitleColor:NavBarItemColor forState:UIControlStateNormal];
  124. UIBarButtonItem *menuButton2 = [[UIBarButtonItem alloc] initWithCustomView:button2];
  125. self.navigationItem.rightBarButtonItem = menuButton2;
  126. }
  127. -(void)cancelSearch
  128. {
  129. [_searchBar resignFirstResponder];
  130. }
  131. -(void) removeCancel
  132. {
  133. self.navigationItem.rightBarButtonItem = nil;
  134. }
  135. #pragma mark search bar delegate
  136. - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
  137. {
  138. return YES;
  139. }
  140. - (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
  141. {
  142. return YES;
  143. }
  144. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  145. {
  146. if ([searchText isEqualToString:@""]) {
  147. self.filterArr = _searchArr;
  148. [_model setShareAndCommentArr:_filterArr ];
  149. [_tableView reloadData];
  150. return;
  151. }
  152. NSString *keyName = @"UserName";
  153. //< 模糊查找
  154. NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K CONTAINS[cd] %@", keyName, searchText];
  155. //< 精确查找
  156. // NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K == %@", keyName, searchText];
  157. NSLog(@"predicate %@",predicateString);
  158. NSMutableArray *filteredArray = [NSMutableArray arrayWithArray:[_searchArr filteredArrayUsingPredicate:predicateString]];
  159. self.filterArr = filteredArray;
  160. [_model setShareAndCommentArr:_filterArr ];
  161. [_tableView reloadData];
  162. }
  163. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  164. {
  165. [searchBar resignFirstResponder];
  166. [self cancelSearch];
  167. }
  168. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  169. {
  170. [_searchBar resignFirstResponder];
  171. [self cancelSearch];
  172. }
  173. @end