This commit is contained in:
Yao
2025-01-11 15:54:19 +08:00
parent 1095c32599
commit 36ca0e65b5
8 changed files with 63 additions and 28 deletions

View File

@@ -17,6 +17,7 @@
#import <SDWebImage.h>
#import "DataModels.h"
#import "UIButton+DSButtonBlock.h"
#import <MJRefresh.h>
#import "MainOldViewController.h"
@@ -32,6 +33,8 @@ static NSString *linkidentifier = @"NotiCenterJumpLinkTableViewCell";
@property (nonatomic, strong) NSString *mainUserId;
@property (nonatomic, strong) NSMutableArray *notiArray;
@property (nonatomic, assign) NSInteger page;
@end
@implementation NotiCenterViewController
@@ -56,16 +59,22 @@ static NSString *linkidentifier = @"NotiCenterJumpLinkTableViewCell";
[self.tableView registerNib:[UINib nibWithNibName:@"NotiCenterContentTableViewCell" bundle:nil] forCellReuseIdentifier:contentidentifier];
[self.tableView registerNib:[UINib nibWithNibName:@"NotiCenterImageTableViewCell" bundle:nil] forCellReuseIdentifier:imageidentifier];
[self.tableView registerNib:[UINib nibWithNibName:@"NotiCenterJumpLinkTableViewCell" bundle:nil] forCellReuseIdentifier:linkidentifier];
self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
self.notiArray = @[].mutableCopy;
self.page = 1;
[self refreshDatasource];
}];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.tableFooterView = [UIView new];
self.notiArray = @[].mutableCopy;
[self setupDatasource];
self.page = 1;
[self refreshDatasource];
}
-(void)setupDatasource
-(void)refreshDatasource
{
NSString *urlstring = [NSString stringWithFormat:@"%@?userId=%@&page=1&size=100",PushRecordsURL,self.mainUserId];
NSString *urlstring = [NSString stringWithFormat:@"%@?userId=%@&page=%ld&size=20",PushRecordsURL,self.mainUserId,(long)self.page];
NSURL *url = [NSURL URLWithString:urlstring];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
@@ -85,17 +94,28 @@ static NSString *linkidentifier = @"NotiCenterJumpLinkTableViewCell";
}else{
if (ISNULL(error) && !ISNULL(responseObject) && [[responseObject objectForKey:@"code"] integerValue] == 1) {
PushRecordDataModel *model = [[PushRecordDataModel alloc] initWithDictionary:responseObject];
for (PushRecordList *list in self.notiArray) {
for (PushRecordList *list in model.data.list) {
if (list.type == 2) {
list.imageHeight = SCREEN_WIDTH-30;
}
}
[self.notiArray addObjectsFromArray:model.data.list];
if (model.data.list.count == 20) {
self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
self.page++;
[self refreshDatasource];
}];
}else{
self.tableView.mj_footer = nil;
}
[self.tableView reloadData];
[self refreshImageDatasource];
[self scrollViewToRecordIDSection];
}
}
}
[self.tableView.mj_header endRefreshing];
[self.tableView.mj_footer endRefreshing];
});
}];
[dataTask resume];
@@ -103,16 +123,35 @@ static NSString *linkidentifier = @"NotiCenterJumpLinkTableViewCell";
-(void)refreshImageDatasource
{
for (PushRecordList *list in self.notiArray) {
for (NSInteger i=0; i<self.notiArray.count; i++) {
PushRecordList *list = self.notiArray[i];
NSURL *url = [NSURL URLWithString:list.image];
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:url completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
if (image && error == nil) {
list.imageHeight = (SCREEN_WIDTH-30)*image.size.height/image.size.width;
if (list.isOpen == YES) {
[self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:1 inSection:i]] withRowAnimation:(UITableViewRowAnimationNone)];
}
}
}];
}
}
-(void)scrollViewToRecordIDSection
{
if (self.pushId > 0) {
for (NSInteger i=0; i<self.notiArray.count; i++) {
PushRecordList *list = self.notiArray[i];
if (list.recordId == self.pushId) {
list.isOpen = YES;
[self.tableView reloadData];
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:i] atScrollPosition:(UITableViewScrollPositionNone) animated:YES];
break;
}
}
}
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.notiArray.count;
@@ -130,20 +169,6 @@ static NSString *linkidentifier = @"NotiCenterJumpLinkTableViewCell";
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// PushRecordList *list = self.notiArray[indexPath.section];
// if (list.isOpen == YES) {
// if (indexPath.row == 0) {
// return UITableViewAutomaticDimension;
// }else{
// if (list.type == 2) {
// return list.imageHeight;
// }else{
// return UITableViewAutomaticDimension;
// }
// }
// }else{
// return UITableViewAutomaticDimension;
// }
return UITableViewAutomaticDimension;
}