FaqViewController.m 7.3 KB

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