123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427 |
- //
- #import "MyMsgVC.h"
- #import "STSegView.h"
- #import "STCell.h"
- #import "TopicVC.h"
- @interface MyMsgVC ()<UITableViewDataSource,UITableViewDelegate,STSegViewDelegate>
- {
- /**左右table。tag分别为0,2
- */
- UITableView *myTableView,* myTableView2;
- int currentPage,currentPage2;
-
- NSMutableArray* models,*models2;
-
- /**每次下载后。就判断.
- 如果cnt为0就显示。否则隐藏
- */
- UIView* placeHolder,* placeHolder2;
-
- STSegView* segV;
-
- UIScrollView* scroll;
- }
- @end
- @implementation MyMsgVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self myInit];
-
- [MBProgressHUD showLoadToView:self.view];
- [self getMessageInfos];
- [self getMyMessagesOnFavAndPoints];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- -(void)viewDidAppear:(BOOL)animated
- {
- [super viewDidAppear:animated];
- }
- #pragma mark -
- -(void)myInit
- {
- [self.view setBackgroundColor:backGroundColor];
- [self setTitle:@"消息"];
- if (_isNotification == NO)
- {
- //正常状态要dismiss回去
- [self configNavigationBar];
- }
- else
- {
- //推送状态 要将根视图变回去
- UIBarButtonItem* backBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"question_pre_checked_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(dismissNavgation)];
- [backBtn setTintColor:defGreen];
- self.navigationController.navigationBar.translucent = NO;
- [self.navigationItem setLeftBarButtonItem:backBtn];
- }
-
- currentPage = currentPage2 = 1;
- models = [NSMutableArray array];
- models2 = [NSMutableArray array];
-
- CGFloat x,y,w,h;
- x = y =0;
- w = kSize.width;
- h = 45;
-
- //自定义分段显示控件
- segV = [[STSegView alloc] initWithFrame:CGRectMake(x, y, w, h)];
- [segV addSelfViewWithRect:CGRectMake(0, h-1, kSize.width, 1) Color:KlineColor];
-
- y = h;
-
- [segV setTitles:@[@"回复与赞",@"系统消息"]];
- [segV setDelegate:self];
- [segV setBackgroundColor:[UIColor whiteColor]];
- [self.view addSubview:segV];
-
- scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, y, kSize.width, kSize.height - y - kNavOffSet) ];
- scroll.showsHorizontalScrollIndicator = NO;
- [self.view addSubview:scroll];
- [scroll setContentSize:CGSizeMake(kSize.width*2, 0)];
- [scroll setTag:1];
- [scroll setPagingEnabled:YES];
- [scroll setDelegate:self];
-
- UITableView* tv ;
- tv = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height - y - kNavOffSet) style:UITableViewStyleGrouped];
- tv.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, .1, .1)];
- tv.estimatedSectionHeaderHeight = 0;
- [scroll addSubview:tv];
- myTableView = tv;
- [tv setBackgroundColor:backGroundColor];
- [tv setTableFooterView:[UIView new]];
- [tv setTag:0];
-
- tv = [[UITableView alloc] initWithFrame:CGRectMake(kSize.width, 0, kSize.width, kSize.height - y - kNavOffSet) style:UITableViewStyleGrouped];
- tv.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, .1, .1)];
- tv.estimatedSectionHeaderHeight = 0;
- [scroll addSubview:tv];
- myTableView2 = tv;
- [tv setBackgroundColor:backGroundColor];
- [tv setTableFooterView:[UIView new]];
- [tv setTag:2];
-
- if (_isNotification == YES)
- {
- //如果推送 默认进入系统消息
- segV.selectedIndex = 1;
- [scroll setContentOffset:CGPointMake(kSize.width, 0)];
- }
-
- //placeHolder
- y = 0;
- UIView* vi = [[UIView alloc] initWithFrame:CGRectMake(0, y, kSize.width, kSize.height - y - kNavOffSet)];
- [scroll addSubview:vi];
- vi.hidden = NO;
- placeHolder = vi;
-
- w = h = kSize.width/3.0;
- x = y = w;
- UIImageView* iv = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
- [iv setImage:[UIImage imageNamed:@"community4.png"]];
- [iv setContentMode:UIViewContentModeScaleAspectFit];
- [placeHolder addSubview:iv];
-
- y += h + 20;
- x = 0;
- w = kSize.width;
- h = 40;
- UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
- [label setText:@"您暂无相关消息~"];
- [label setTextAlignment:NSTextAlignmentCenter];
- [label setTextColor:contentTextColor];
- [placeHolder addSubview:label];
-
-
- //placeHolder2
- y = 0;
- vi = [[UIView alloc] initWithFrame:CGRectMake(kSize.width, y, kSize.width, kSize.height - y - kNavOffSet)];
- [scroll addSubview:vi];
- vi.hidden = NO;
- placeHolder2 = vi;
- w = h = kSize.width/3.0;
- x = y = w;
- iv = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
- [iv setImage:[UIImage imageNamed:@"community4.png"]];
- [iv setContentMode:UIViewContentModeScaleAspectFit];
- [placeHolder2 addSubview:iv];
-
- y += h + 20;
- x = 0;
- w = kSize.width;
- h = 40;
- label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)];
- [label setText:@"您暂无相关消息~"];
- [label setTextAlignment:NSTextAlignmentCenter];
- [label setTextColor:contentTextColor];
- [placeHolder2 addSubview:label];
- }
- -(void)dismissNavgation
- {
- //推送过来 返回主页面
- [myDelegate gotoLoad];
- }
- -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
- {
- if ( 1 == scrollView.tag) {
- CGPoint off = scroll.contentOffset;
- [segV setSelectedIndex:(off.x / kSize.width)];
- return;
- }
-
- CGPoint off = scrollView.contentOffset;
- if (scrollView.contentSize.height - off.y - scrollView.frame.size.height < 1) {
-
- [scrollView setContentOffset:CGPointMake(off.x, off.y - 10) animated:YES];
- //NSLog(@"AT bottom");
- [MBProgressHUD showLoadToView:self.view];
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
-
- if (0 == scrollView.tag) {
- [self getMyMessagesOnFavAndPoints];
- }
- if (2 == scrollView.tag) {
- [self getMessageInfos];
- }
- });
- }
-
- }
- -(void)didSelectedIndex:(NSInteger)index
- {
- [scroll setContentOffset:CGPointMake(kSize.width*index, 0) animated:YES];
- }
- #pragma mark -
- -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- return .1;
- }
- -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
- {
- UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 10)];
- [v setBackgroundColor:[UIColor colorWithWhite:.96 alpha:1]];
- return v;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- {
- return 10;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath
- {
- if (tableView.tag == 0){
- return 70;
- }else{
-
- NSDictionary *dic = models2[indexPath.section];
- NSString *str = dic[@"CONTENT"];
- CGFloat height = [str heightForWid:kSize.width - 100 Font:18];
- if (height < 60.0) {
- height = 60;
- }
- return height + 50;
- }
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return 1;
- }
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- if ( 0 == tableView.tag) {
- return models.count;
- }else{
- return models2.count;
- }
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- STCell* cell = [STCell cellForTableView:tableView];
- [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
-
- if (0 == tableView.tag) {
- //评论点赞
- [cell setModelReply:models[indexPath.section]];
- }else{
- //消息
- [cell setModel:models2[indexPath.section]];
- }
- return cell;
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- if (0 == tableView.tag) {
-
- NSDictionary *obj = models[indexPath.section];
- TopicVC* vc = [[TopicVC alloc] init];
- [vc setTopicId:obj[@"TOPICID"]];
- [self navPushHideTabbarToVC:vc];
- }
- }
- #pragma mark - 这是异步加载 只不过刚进来是在主线程中的异步加载
- /**系统消息
- */
- -(void)getMessageInfos
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
- NSMutableArray *arr=[NSMutableArray array];
- NSString *idStr = defUser.userDict[@"id"];
- if (!idStr || [idStr isEqualToString:@""]) {
- return;
- }
- [arr addPro:@"user" Value:defUser.userDict[@"id"]];
- [arr addPro:@"msgType" Value:@""];
- [arr addPro:@"userType" Value:@"1"];
- [arr addPro:@"isPage" Value:@"1"];
- [arr addPro:@"pageSize" Value:@"10"];
- [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",currentPage2]];
-
- NSString* method = @"getMessageInfos";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
-
- [MBProgressHUD hideHUDForView:self.view];
- //NSLog(@"getMessageInfos系统----%@",dict);
-
- if (!dict) {
- ShowMsgFailed();
- return;
- }
- if ( [dict[@"code"] isEqualToString:@"1"]) {
- ShowMsg(dict[@"body"]);
- return;
- }
- NSArray* json = dict[@"body"];
-
- if (json.count > 0) {
- [models2 addObjectsFromArray:json];
- currentPage2 ++;
- }else{
- if (currentPage2 > 1) {
- ShowMsg(@"已加载全部");
- }
- }
- // NSLog(@"models2cnt------%d",(int)models2.count);
-
- if (models2.count < 1) {
- placeHolder2.hidden = NO;
- }else{
- placeHolder2.hidden = YES;
- [myTableView2 setDelegate:self];
- [myTableView2 setDataSource:self];
- [myTableView2 reloadData];
- }
- }];
- }
- /**回复与赞
- */
- -(void)getMyMessagesOnFavAndPoints
- {
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"user" Value:defUser.userDict[@"id"]];
- [arr addPro:@"isPage" Value:@"1"];
- [arr addPro:@"pageSize" Value:@"10"];
- [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",currentPage]];
-
- NSString* method = @"getMyMessagesOnFavAndPoints";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
-
- [MBProgressHUD hideHUDForView:self.view];
- if (!dict) {
- ShowMsgFailed();
- return;
- }
- if ( [dict[@"code"] isEqualToString:@"1"]) {
- ShowMsg(dict[@"body"]);
- return;
- }
- NSArray* json = dict[@"body"];
- if (json.count > 0) {
- [models addObjectsFromArray:json];
- currentPage ++;
- }else{
- //一定要加上这个判断 要不然 这个展示信息在主线程 请求也在主线程 会卡塞线程的
- if (currentPage > 1) {
- ShowMsg(@"已加载全部");
- }
- }
-
- if (models.count < 1) {
- placeHolder.hidden = NO;
- }else{
- placeHolder.hidden = YES;
- [myTableView setDelegate:self];
- [myTableView setDataSource:self];
- [myTableView reloadData];
- }
- }];
- }
- @end
|