FavTopicsVC.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //
  2. #import "FavTopicsVC.h"
  3. #import "FavCell.h"
  4. #import "TopicVC.h"
  5. @interface FavTopicsVC ()<UITableViewDataSource,UITableViewDelegate>
  6. {
  7. UITableView* myTableView;
  8. NSArray* models;
  9. /**每次下载后。就判断.
  10. 如果cnt为0就显示。否则隐藏
  11. */
  12. UIView* placeHolder;
  13. }
  14. @end
  15. @implementation FavTopicsVC
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. [self myInit];
  19. [self getMyTopicFavs];
  20. }
  21. - (void)didReceiveMemoryWarning {
  22. [super didReceiveMemoryWarning];
  23. // Dispose of any resources that can be recreated.
  24. }
  25. -(void)viewDidAppear:(BOOL)animated
  26. {
  27. [super viewDidAppear:animated];
  28. }
  29. #pragma mark -
  30. -(void)myInit
  31. {
  32. [self configNavigationBar];
  33. [self setTitle:@"收藏"];
  34. //这是一个请求为空的界面 教练列表可以放一个
  35. UITableView* tv = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height - kNavOffSet)];
  36. [self.view addSubview:tv];
  37. myTableView = tv;
  38. [myTableView setDelegate:self];
  39. [myTableView setDataSource:self];
  40. [tv setTableFooterView:[UIView new]];
  41. CGFloat x,y,w,h;
  42. y = 0;
  43. //placeHolder
  44. UIView* vi = [[UIView alloc] initWithFrame:CGRectMake(0, y, kSize.width, kSize.height - y - kNavOffSet)];
  45. [self.view addSubview:vi];
  46. vi.hidden = YES;
  47. placeHolder = vi;
  48. w = h = kSize.width/3.0;
  49. x = y = w;
  50. UIImageView* iv = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
  51. [iv setImage:[UIImage imageNamed:@"community4.png"]];
  52. [iv setContentMode:UIViewContentModeScaleAspectFit];
  53. [placeHolder addSubview:iv];
  54. y += h + 20;
  55. x = 0;
  56. w = kSize.width;
  57. h = 40;
  58. UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
  59. [label setText:@"您还没有收藏话题呢~"];
  60. [label setTextAlignment:NSTextAlignmentCenter];
  61. [label setTextColor:contentTextColor];
  62. [placeHolder addSubview:label];
  63. }
  64. #pragma mark -
  65. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  66. {
  67. return FavCellHeightByDict(models[indexPath.row]);
  68. }
  69. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  70. {
  71. return models.count;
  72. }
  73. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  74. {
  75. FavCell* cell = [FavCell cellForTableView:tableView];
  76. [cell setModel:models[indexPath.row]];
  77. return cell;
  78. }
  79. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  80. {
  81. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  82. NSDictionary * obj = models[indexPath.row];
  83. TopicVC* vc = [[TopicVC alloc] init];
  84. [vc setTopicId:obj[@"ID"]];
  85. vc.userId = obj[@"TI_CRUSER"];
  86. [self navPushHideTabbarToVC:vc];
  87. }
  88. #pragma mark -
  89. -(void)getMyTopicFavs
  90. {
  91. if (![Util connectedToNetWork]) {
  92. showMsgUnconnect();
  93. return;
  94. }
  95. placeHolder.hidden = NO;
  96. NSMutableArray *arr=[NSMutableArray array];
  97. [arr addPro:@"user" Value:defUser.userDict[@"id"]];
  98. [arr addPro:@"isPage" Value:@"1"];
  99. [arr addPro:@"pageSize" Value:@"10"];
  100. [arr addPro:@"currentPage" Value:@"1"];
  101. NSString* method = @"getMyTopicFavs";
  102. [MBProgressHUD showLoadToView:self.view];
  103. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  104. [MBProgressHUD hideHUDForView:self.view];
  105. //NSLog(@"收藏列表---->%@",dict);
  106. if (!dict) {
  107. ShowMsgFailed();
  108. return;
  109. }
  110. if ( [dict[@"code"] isEqualToString:@"1"]) {
  111. ShowMsg(dict[@"body"]);
  112. return;
  113. }
  114. NSArray* json = dict[@"body"];
  115. models = json;
  116. if (json.count != 0) {
  117. placeHolder.hidden = YES;
  118. }
  119. [myTableView reloadData];
  120. }];
  121. }
  122. @end