Commit 54a3efee authored by admin's avatar admin

修复公告不显示

parent 1b1906b8
......@@ -12,6 +12,8 @@
#import "AnnounceModel.h"
#import "AnnoDetailViewController.h"
#import "NoDataView.h"
#import <MBProgressHUD.h>
#define kAnnoTableViewCell @"AnnoTableViewCell"
......@@ -23,6 +25,8 @@
@property (nonatomic, strong) NSString *stateStr;
@property (nonatomic, assign) BOOL isRead;
@property (nonatomic, strong) NoDataView *noDataView;
@property (nonatomic, strong) NSMutableArray *allAnnoArray;
@end
......@@ -69,10 +73,9 @@
NSString *user_uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"];
int page_number = 0;
int page_size = 10;
//NSString *url = [NSString stringWithFormat:@"%@%@%@?read=%@&page_number=%d&page_size=%d", kRedStarURL, kAnnounceListURL ,user_uuid ,_stateStr, page_number, page_size];
NSString *url = [NSString stringWithFormat:@"%@%@%@?page_number=%d&page_size=%d", kRedStarURL, kAnnounceListURL ,user_uuid, page_number, page_size];
NSString *url = [NSString stringWithFormat:@"%@%@%@?read=%@&page_number=%d&page_size=%d", kRedStarURL, kAnnounceListURL ,user_uuid ,_stateStr, page_number, page_size];
NSLog(@"urlll = %@", url);
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
HttpClient *httpClient = [[HttpClient alloc] initWithUrl:url];
[httpClient getAnnounceListWithCompletion:^(id response, NSError *error) {
NSLog(@"公告response = %@", response);
......@@ -82,11 +85,17 @@
for (NSDictionary *annoDict in array) {
AnnounceModel *anno = [AnnounceModel announceModelWithDict:annoDict];
[_allAnnoArray addObject:anno];
}
if (_allAnnoArray.count == 0) {
self.noDataView.backgroundColor = [UIColor whiteColor];
[MBProgressHUD hideHUDForView:self.view animated:YES];
} else {
self.tableView.delegate = self;
self.tableView.dataSource = self;
[MBProgressHUD hideHUDForView:self.view animated:YES];
}
}
}];
}
......@@ -123,7 +132,6 @@
- (void)segmentChangedValue:(UISegmentedControl *)sender
{
NSString *url;
NSString *user_uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"];
int page_number = 0;
......@@ -140,8 +148,9 @@
}
NSLog(@"url ==== %@", url);
NSLog(@"22url ==== %@", url);
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
HttpClient *httpClient = [[HttpClient alloc] initWithUrl:url];
[httpClient getAnnounceListWithCompletion:^(id response, NSError *error) {
NSLog(@"segemnt 公告 = %@ error = %@", response, error);
......@@ -153,10 +162,29 @@
AnnounceModel *anno = [AnnounceModel announceModelWithDict:annoDict];
[annoArray addObject:anno];
}
_allAnnoArray = annoArray;
_allAnnoArray = [NSMutableArray arrayWithArray:annoArray];
}
[self.tableView reloadData];
if (_allAnnoArray.count == 0) {
if (_tableView) {
[_tableView removeFromSuperview];
_tableView = nil;
}
self.noDataView.backgroundColor = [UIColor whiteColor];
[MBProgressHUD hideHUDForView:self.view animated:YES];
} else {
if (_noDataView) {
[_noDataView removeFromSuperview];
_noDataView = nil;
}
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.tableView reloadData];
[MBProgressHUD hideHUDForView:self.view animated:YES];
}
}];
......@@ -274,4 +302,26 @@
return _tableView;
}
- (NoDataView *)noDataView
{
if (!_noDataView) {
_noDataView = [[NoDataView alloc] init];
_noDataView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:_noDataView];
NSLayoutConstraint *tableTop = [NSLayoutConstraint constraintWithItem:_noDataView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.bgBar attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
[self.view addConstraint:tableTop];
NSLayoutConstraint *tableLeft = [NSLayoutConstraint constraintWithItem:_noDataView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
[self.view addConstraint:tableLeft];
NSLayoutConstraint *tableRight = [NSLayoutConstraint constraintWithItem:_noDataView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
[self.view addConstraint:tableRight];
NSLayoutConstraint *tableBottom = [NSLayoutConstraint constraintWithItem:_noDataView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
[self.view addConstraint:tableBottom];
}
return _noDataView;
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment