ForumViewController.m 4.01 KB
Newer Older
1 2 3 4 5 6 7 8 9
//
//  ForumViewController.m
//  Lighting
//
//  Created by 曹云霄 on 2016/11/24.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "ForumViewController.h"
10
#import "ForumTableViewCell.h"
曹云霄's avatar
曹云霄 committed
11 12
#import "ForumItemListViewController.h"

13

曹云霄's avatar
曹云霄 committed
14
@interface ForumViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>
15

曹云霄's avatar
曹云霄 committed
16
@property (nonatomic,strong) ForumCategoryResponse *category;
17

曹云霄's avatar
曹云霄 committed
18

19 20 21 22
@end

@implementation ForumViewController

曹云霄's avatar
曹云霄 committed
23 24 25 26 27
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self getForumAllTypeAction];
}

28 29
- (void)viewDidLoad {
    [super viewDidLoad];
30 31
    
    [self setUpForumTableView];
32
    [self setUpRefreshAction];
33 34
}

35 36 37 38 39
#pragma mark - UITableView
- (void)setUpForumTableView
{
    self.forumTableView.tableFooterView = [UIView new];
    self.forumTableView.rowHeight = 90;
40 41 42 43 44 45 46 47
    [Notification addObserver:self selector:@selector(refreshForumList:) name:REFRESH_FROUMLIST object:nil];
}

#pragma mark -选中时间轴刷新列表
- (void)refreshForumList:(NSNotification *)object
{
    self.typeId = object.object;
    [self.forumTableView.mj_header beginRefreshing];
48 49
}

50 51 52 53 54 55 56 57 58 59 60 61
#pragma mark - 设置刷新
- (void)setUpRefreshAction
{
    WS(weakSelf);
    MjRefreshHeaderCustom *headerRefresh = [MjRefreshHeaderCustom headerWithRefreshingBlock:^{
        [weakSelf getForumAllTypeAction];
    }];
    headerRefresh.stateLabel.hidden = YES;
    headerRefresh.lastUpdatedTimeLabel.hidden = YES;
    self.forumTableView.mj_header =headerRefresh;
}

62 63 64 65
#pragma mark - 获取论坛项Type
- (void)getForumAllTypeAction
{
    WS(weakSelf);
66
    [XBLoadingView showHUDViewWithDefault];;
曹云霄's avatar
曹云霄 committed
67
    [HTTP networkWithDictionaryRequestWithURL:[NSString stringWithFormat:SERVERREQUESTURL(FORUMCATEGORYS),self.typeId,[Shoppersmanager manager].shoppers.employee.fid] withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
68
        
69
        [XBLoadingView hideHUDViewWithDefault];
70
        [weakSelf endRefreshingForTableView:weakSelf.forumTableView];
曹云霄's avatar
曹云霄 committed
71 72
        weakSelf.forumTableView.emptyDataSetDelegate = weakSelf;
        weakSelf.forumTableView.emptyDataSetSource = weakSelf;
曹云霄's avatar
曹云霄 committed
73
        if (RESULT(returnValue)) {
曹云霄's avatar
曹云霄 committed
74
            weakSelf.category = [[ForumCategoryResponse alloc] initWithDictionary:RESPONSE(returnValue) error:nil];
曹云霄's avatar
曹云霄 committed
75
            [weakSelf.forumTableView reloadData];
76
        }else{
77
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
78
        }
79
    } withFailureBlock:^(NSError *error) {
80
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
81 82 83 84 85 86 87
    }];
}

#pragma mark - <UITableViewDelegate,UITableViewDataSource>
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ForumTableViewCell *forumCell = [tableView dequeueReusableCellWithIdentifier:@"ForumTableViewCell" forIndexPath:indexPath];
曹云霄's avatar
曹云霄 committed
88
    forumCell.categoryEntity = self.category.categories[indexPath.row];
89 90
    return forumCell;
}
91

92 93
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
曹云霄's avatar
曹云霄 committed
94
    return self.category.categories.count;
95
}
96 97 98

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
99
    ForumItemListViewController  *itemListVc = [[[self class] getLearningCenterStoryboardClass] instantiateViewControllerWithIdentifier:@"ForumItemListViewController"];
100 101 102
    TOForumCategoryEntity *category = self.category.categories[indexPath.row];
    category.typeId = self.typeId;
    itemListVc.category = category;
103
    itemListVc.isPosting = [category.name isEqualToString:@"欧普问问"]?0:1;
曹云霄's avatar
曹云霄 committed
104
    [self.navigationController pushViewController:itemListVc animated:YES];
105 106
}

107

曹云霄's avatar
曹云霄 committed
108 109 110 111 112 113
#pragma mark -释放
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

曹云霄's avatar
曹云霄 committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
#pragma mark -友好界面
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
    return kNoDataImage;
}

- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
{
    return YES;
}

- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
    return  64.0;
}


130
@end