FaqViewController.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. }
  31. - (void)initUI {
  32. [self initTableViewAsDefaultStyle:_tableView];
  33. _noContentView.hidden = NO;
  34. _tableView.hidden = YES;
  35. [self initRefreshController];
  36. }
  37. - (void)initRefreshController {
  38. //set refresh controls
  39. __weak typeof(self) weakSelf = self;
  40. self.refreshController = [[JYPullToRefreshController alloc] initWithScrollView:self.tableView];
  41. self.refreshController.pullToRefreshHandleAction = ^{
  42. [weakSelf requestFaqListRecently];
  43. };
  44. self.loadMoreController = [[JYPullToLoadMoreController alloc] initWithScrollView:self.tableView];
  45. self.loadMoreController.enable = NO;
  46. self.loadMoreController.pullToLoadMoreHandleAction = ^{
  47. [weakSelf requestFaqListOlder];
  48. };
  49. }
  50. - (void)prepareViewDidLoad {
  51. [self requestFaqList];
  52. }
  53. - (void)requestFaqListRecently {
  54. FaqModel *faq = [_faqList firstObject];
  55. _pagingType = ksListPagingTypeUpward;
  56. _pagingId = faq.faqId;
  57. [self performSelector:@selector(requestFaqList) withObject:nil afterDelay:0.0f];
  58. }
  59. - (void)requestFaqListOlder {
  60. FaqModel *faq = [_faqList lastObject];
  61. _pagingType = ksListPagingTypeDownward;
  62. _pagingId = faq.faqId;
  63. [self performSelector:@selector(requestFaqList) withObject:nil afterDelay:0.0f];
  64. }
  65. - (void)requestFaqList{
  66. // NSDictionary *parameter = @{@"member_id":[JDFacade facade].loginUser.memberId,
  67. // @"faq_id": _pagingId ? _pagingId : ksEmptyString,
  68. // @"paging_type": _pagingType ? _pagingType : ksEmptyString,
  69. // @"read_datetime": [JDFacade facade].loginUser.noticeReadTime ? [JDFacade facade].loginUser.noticeReadTime : ksEmptyString};
  70. NSDictionary *parameter = @{@"faq_id": _pagingId ? _pagingId : ksEmptyString,
  71. @"paging_type" : ksEmptyString,
  72. @"read_datetime" : ksEmptyString};
  73. NSString *path = API_GET_FAQ;
  74. // NSString *path = [[JDFacade facade] getUrlWithCustAndGroupID:API_GET_FAQ arguments:nil];
  75. [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[FaqListModel class] completion:^(id responseObject) {
  76. if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
  77. return;
  78. }
  79. NSLog(@"FAQ List : %@", responseObject);
  80. FaqListModel *fetchedFaqList = (FaqListModel *) responseObject;
  81. if (fetchedFaqList && fetchedFaqList.faqList && fetchedFaqList.faqList.count) { // API 성공
  82. // NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:0];
  83. if (_pagingType && [_pagingType isEqualToString:ksListPagingTypeUpward]) {
  84. // [_faqList insertObjects:fetchedFaqList.faqList atIndexes:indexSet];
  85. } else {
  86. [_faqList addObjectsFromArray:fetchedFaqList.faqList];
  87. }
  88. //테이블 컨텐츠가 없을 경우,
  89. if (_tableView.hidden) {
  90. // [_mainView bringSubviewToFront:_tableView];
  91. _noContentView.hidden = YES;
  92. _tableView.hidden = NO;
  93. }
  94. [_tableView reloadData];
  95. } else {
  96. if (!_faqList.count) { //이미 로드된 데이터가 있을 경우는 출력하지 않음.
  97. // [_mainView bringSubviewToFront:_noContentView];
  98. _noContentView.hidden = NO;
  99. _tableView.hidden = YES;
  100. }
  101. }
  102. //refresh control
  103. if (self.refreshController && self.refreshController.refreshState == JYRefreshStateLoading) {
  104. [self.refreshController stopRefreshWithAnimated:YES completion:nil];
  105. }
  106. if (self.loadMoreController) {
  107. [self.loadMoreController stopLoadMoreCompletion:nil];
  108. self.loadMoreController.enable = _faqList.count % kdListPagginSize == 0;
  109. }
  110. } failure:^(id errorObject) {
  111. JDErrorModel *error = (JDErrorModel *)errorObject;
  112. [[JDFacade facade] alert:error.errorMessage];
  113. }];
  114. }
  115. #pragma mark - UITableView DataSource & Delegate
  116. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  117. return 1;
  118. }
  119. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  120. return UITableViewAutomaticDimension;
  121. }
  122. - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
  123. return UITableViewAutomaticDimension;
  124. }
  125. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  126. return _faqList.count;
  127. }
  128. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  129. FaqModel *faq = _faqList[indexPath.row];
  130. FaqTableViewCell *cell = (FaqTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"FaqCellIdentifier"];
  131. cell.lblCount.text = [NSString stringWithFormat:@"%lu%@",(_faqList.count - indexPath.row),@"."];
  132. cell.lblContent.text = faq.title;
  133. return cell;
  134. }
  135. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  136. FaqModel *faq = _faqList[indexPath.row];
  137. FaqDetailViewController *vc =[CommonUtil instantiateViewControllerWithIdentifier:@"FaqDetailViewController" storyboardName:@"Main"];
  138. NSString *detail_count =[NSString stringWithFormat:@"%lu",(_faqList.count - indexPath.row)];
  139. // vc.detail_Url = select_faq.detailUrl;
  140. // _detailUrl = select_faq.detailUrl;
  141. vc.faqModel = faq;
  142. vc.detail_count = detail_count;
  143. [self presentViewController:vc animated:YES completion:nil];
  144. }
  145. #pragma mark - UI Events
  146. - (IBAction)btnCloseTouched:(id)sender {
  147. [self dismissViewControllerAnimated:YES completion:nil];
  148. }
  149. - (void)didReceiveMemoryWarning {
  150. [super didReceiveMemoryWarning];
  151. }
  152. @end