FaqViewController.m 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. //
  2. // FaqViewController.m
  3. // OneCable
  4. //
  5. // Created by nComz on 2017. 4. 4..
  6. // Copyright © 2017년 ntels. All rights reserved.
  7. //
  8. #import "FaqViewController.h"
  9. #import "CustomTableView.h"
  10. #import "CustomImageView.h"
  11. #import "JYRefreshController.h"
  12. #import "RequestHandler.h"
  13. #import "FaqDetailViewController.h"
  14. @implementation FaqTableViewCell
  15. @end
  16. @interface FaqViewController () {
  17. NSMutableArray<FaqModel> *_faqList;
  18. NSString *_pagingId, *_pagingType;
  19. NSDate *_prevReadTime;
  20. }
  21. @property (strong, nonatomic) JYPullToRefreshController *refreshController;
  22. @property (strong, nonatomic) JYPullToLoadMoreController *loadMoreController;
  23. @end
  24. @implementation FaqViewController
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. _faqList = [(NSMutableArray<FaqModel> *)[NSMutableArray alloc] init];
  28. [self initUI];
  29. [self prepareViewDidLoad];
  30. // [self performSelector:@selector(testFAQDetailViewContrller) withObject:nil afterDelay:3.0f];
  31. }
  32. //-(void)testFAQDetailViewContrller{
  33. // FaqModel *select_faq =[[FaqModel alloc]init];
  34. //
  35. // select_faq.faqId =@"001";
  36. // select_faq.title = @"테스트 제목";
  37. // select_faq.detailUrl = @"http://m.daum.net/";
  38. //
  39. // FaqDetailViewController *vc =[CommonUtil instantiateViewControllerWithIdentifier:@"FaqDetailViewController" storyboardName:@"Main"];
  40. //
  41. // vc.m_faq = select_faq;
  42. //
  43. // [self presentViewController:vc animated:YES completion:nil];
  44. //}
  45. - (void)didReceiveMemoryWarning {
  46. [super didReceiveMemoryWarning];
  47. }
  48. //- (void)viewWillAppear:(BOOL)animated {
  49. // [super viewWillAppear:animated];
  50. //
  51. // [self requestFaqList];
  52. //}
  53. - (void)initUI {
  54. [self initTableViewAsDefaultStyle:_tableView];
  55. _noContentView.hidden = NO;
  56. _tableView.hidden = YES;
  57. [self initRefreshController];
  58. }
  59. - (void)initRefreshController {
  60. //set refresh controls
  61. __weak typeof(self) weakSelf = self;
  62. // self.refreshController = [[JYPullToRefreshController alloc] initWithScrollView:self.tableView];
  63. // self.refreshController.pullToRefreshHandleAction = ^{
  64. // [weakSelf requestNoticeList];
  65. // };
  66. self.refreshController = [[JYPullToRefreshController alloc] initWithScrollView:self.tableView];
  67. self.refreshController.pullToRefreshHandleAction = ^{
  68. [weakSelf requestFaqListRecently];
  69. };
  70. self.loadMoreController = [[JYPullToLoadMoreController alloc] initWithScrollView:self.tableView];
  71. self.loadMoreController.enable = NO;
  72. self.loadMoreController.pullToLoadMoreHandleAction = ^{
  73. [weakSelf requestFaqListOlder];
  74. };
  75. }
  76. - (void)prepareViewDidLoad {
  77. [self requestFaqList];
  78. }
  79. - (void)requestFaqListRecently {
  80. NoticeModel *notice = [_faqList firstObject];
  81. _pagingType = ksListPagingTypeUpward;
  82. _pagingId = notice.noticeId;
  83. [self performSelector:@selector(requestFaqList) withObject:nil afterDelay:0.0f];
  84. }
  85. - (void)requestFaqListOlder {
  86. NoticeModel *notice = [_faqList lastObject];
  87. _pagingType = ksListPagingTypeDownward;
  88. _pagingId = notice.noticeId;
  89. [self performSelector:@selector(requestFaqList) withObject:nil afterDelay:0.0f];
  90. }
  91. - (void)requestFaqList{
  92. NSDictionary *parameter = @{@"faq_id": _pagingId ? _pagingId : ksEmptyString,
  93. @"paging_type": _pagingType ? _pagingType : ksEmptyString,
  94. @"read_datetime": [JDFacade facade].loginUser.noticeReadTime ? [JDFacade facade].loginUser.noticeReadTime : ksEmptyString};
  95. // NSString *path = API_GET_FAQ;
  96. NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_GET_FAQ arguments:nil];
  97. [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:parameter modelClass:[FaqListModel class] completion:^(id responseObject) {
  98. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  99. return;
  100. }
  101. NSLog(@"FAQ List : %@", responseObject);
  102. FaqListModel *fetchedFaqList = (FaqListModel *) responseObject;
  103. if (fetchedFaqList && fetchedFaqList.faqList && fetchedFaqList.faqList.count) { // API 성공
  104. NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:0];
  105. // 수정 팔요
  106. if (_faqList && [_pagingType isEqualToString:ksListPagingTypeUpward]) {
  107. [_faqList insertObjects:fetchedFaqList.faqList atIndexes:indexSet];
  108. } else {
  109. [_faqList addObjectsFromArray:fetchedFaqList.faqList];
  110. }
  111. //테이블 컨텐츠가 없을 경우,
  112. if (_tableView.hidden) {
  113. // [_mainView bringSubviewToFront:_tableView];
  114. _noContentView.hidden = YES;
  115. _tableView.hidden = NO;
  116. }
  117. [_tableView reloadData];
  118. } else {
  119. if (!_faqList.count) { //이미 로드된 데이터가 있을 경우는 출력하지 않음.
  120. // [_mainView bringSubviewToFront:_noContentView];
  121. _noContentView.hidden = NO;
  122. _tableView.hidden = YES;
  123. }
  124. }
  125. //refresh control
  126. if (self.refreshController && self.refreshController.refreshState == JYRefreshStateLoading) {
  127. [self.refreshController stopRefreshWithAnimated:YES completion:nil];
  128. }
  129. if (self.loadMoreController) {
  130. [self.loadMoreController stopLoadMoreCompletion:nil];
  131. self.loadMoreController.enable = _faqList.count % kdListPagginSize == 0;
  132. }
  133. } failure:^(id errorObject) {
  134. JDErrorModel *error = (JDErrorModel *)errorObject;
  135. [[JDFacade facade] alert:error.errorMessage];
  136. }];
  137. }
  138. #pragma mark - UITableView DataSource & Delegate
  139. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  140. return 1;
  141. }
  142. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  143. return UITableViewAutomaticDimension;
  144. }
  145. - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
  146. return UITableViewAutomaticDimension;
  147. }
  148. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  149. return _faqList.count;
  150. }
  151. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  152. FaqModel *faq = _faqList[indexPath.row];
  153. FaqTableViewCell *cell = (FaqTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"FaqCellIdentifier"];
  154. cell.lblCount.text = [NSString stringWithFormat:@"%lu%@",(_faqList.count - indexPath.row),@"."];
  155. cell.lblContent.text = faq.title;
  156. return cell;
  157. }
  158. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  159. FaqModel *select_faq = _faqList[indexPath.row];
  160. FaqDetailViewController *vc =[CommonUtil instantiateViewControllerWithIdentifier:@"FaqDetailViewController" storyboardName:@"Main"];
  161. vc.detail_Url = select_faq.detailUrl;
  162. // _detailUrl = select_faq.detailUrl;
  163. // NSString * detailUrl = select_faq.detailUrl;
  164. // select_faq.detailUrl = detailUrl;
  165. //
  166. // vc.m_faq = select_faq;
  167. [self presentViewController:vc animated:YES completion:nil];
  168. }
  169. //
  170. //- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
  171. //
  172. // NSString* requestUrl = [[request URL] absoluteString];
  173. //
  174. // NSLog(@"webView: shouldStartLoadWithRequest:%@ navigationType:%ld", requestUrl, (long)navigationType);
  175. //
  176. // return YES;
  177. //
  178. //}
  179. //
  180. //- (void)webViewDidStartLoad:(UIWebView *)webView {
  181. //
  182. // NSLog(@"webViewDidStartLoad : %@", [[webView.request URL] absoluteString]);
  183. //
  184. //}
  185. //
  186. //- (void)webViewDidFinishLoad:(UIWebView *)webView {
  187. //
  188. // NSLog(@"webViewDidFinishLoad : %@", [[webView.request URL] absoluteString]);
  189. //
  190. //}
  191. //
  192. //- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
  193. //
  194. //}
  195. #pragma mark - UI Events
  196. - (IBAction)btnCloseTouched:(id)sender {
  197. [self dismissViewControllerAnimated:YES completion:nil];
  198. }
  199. @end