SLMomentsNewsVc.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // SLMomentsNewsVc.m
  3. // SLAiELTS
  4. //
  5. // Created by Gusont on 2023/5/30.
  6. //
  7. #import "SLMomentsNewsVc.h"
  8. #import "SLMomentsNewsCell.h"
  9. #import "SLMomentsNewsModel.h"
  10. #import "SLMomentDetailTableVc.h"
  11. #import "SDTimeLineCellModel.h"
  12. @interface SLMomentsNewsVc ()<UITableViewDelegate, UITableViewDataSource>
  13. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  14. @property (nonatomic, strong) NSMutableArray *newsModels;
  15. @end
  16. @implementation SLMomentsNewsVc
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. // Do any additional setup after loading the view from its nib.
  20. self.title = NSLocalizedString(@"消息", nil);
  21. if (@available(iOS 11.0, *)) {
  22. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  23. } else {
  24. self.automaticallyAdjustsScrollViewInsets = NO;
  25. }
  26. [self.tableView registerNibCellWithReuseIdentifierClass:SLMomentsNewsCell.class];
  27. [[SLHttpCenter SharedInstance] getWithUrl:@"/api/Friend/MessageItemFriend" parameter:@{} success:^(id responseObject) {
  28. NSDictionary *dataArr = [responseObject objectForKey:@"data"];
  29. self.newsModels = [SLMomentsNewsModel mj_objectArrayWithKeyValuesArray:dataArr];
  30. [self.tableView reloadData];
  31. } failure:^(SPRequestError *error) {
  32. }];
  33. }
  34. - (void)rightBarBtnClick {
  35. }
  36. - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
  37. SLMomentsNewsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SLMomentsNewsCell"];
  38. SLMomentsNewsModel *model = [self.newsModels objectAtIndex:indexPath.row];
  39. [cell confignNewsCell:model];
  40. return cell;
  41. }
  42. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  43. SLMomentsNewsModel *model = [self.newsModels objectAtIndex:indexPath.row];
  44. return [model.interType isEqualToString:@"0"] ? 108 : 120;
  45. }
  46. - (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  47. return self.newsModels.count;
  48. }
  49. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  50. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  51. SLMomentsNewsModel *model = [self.newsModels objectAtIndex:indexPath.row];
  52. [[SLHttpCenter SharedInstance] getWithUrl:@"/api/Friend/GetFriendById" parameter:@{@"friendId" : model.friendId} success:^(id responseObject) {
  53. NSDictionary *dict = [responseObject objectForKey:@"data"];
  54. SDTimeLineCellModel *model = [SDTimeLineCellModel mj_objectWithKeyValues:dict];
  55. model.likeItemsArray = [NSMutableArray new];
  56. [model.likeStr enumerateObjectsUsingBlock:^(id _Nonnull obj1, NSUInteger idx1, BOOL * _Nonnull stop) {
  57. SDTimeLineCellLikeItemModel *model1 = [[SDTimeLineCellLikeItemModel alloc] init];
  58. model1.userName = obj1;
  59. model1.userId = @"1111";
  60. [model.likeItemsArray addObject:model1];
  61. }];
  62. SLMomentDetailTableVc *vc = [SLMomentsVc loadViewControllewWithNib];
  63. object_setClass(vc, SLMomentDetailTableVc.class);
  64. vc.isDetail = YES;
  65. vc.dataArray = [NSMutableArray arrayWithObject:model];
  66. [vc.tableView reloadData];
  67. [self navPushViewController:vc animated:YES];
  68. } failure:^(SPRequestError *error) {
  69. }];
  70. }
  71. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  72. return 0.001f;
  73. }
  74. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  75. return 0.001f;
  76. }
  77. - (NSMutableArray *)newsModels {
  78. if (!_newsModels) {
  79. _newsModels = [NSMutableArray array];
  80. }
  81. return _newsModels;
  82. }
  83. @end