ForumViewController.m 2.98 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

14
@interface ForumViewController ()<UITableViewDelegate,UITableViewDataSource>
15

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

18 19 20 21 22 23
@end

@implementation ForumViewController

- (void)viewDidLoad {
    [super viewDidLoad];
24 25
    
    [self setUpForumTableView];
26
    [self setUpRefreshAction];
27 28
}

29 30 31 32 33
#pragma mark - UITableView
- (void)setUpForumTableView
{
    self.forumTableView.tableFooterView = [UIView new];
    self.forumTableView.rowHeight = 90;
34 35
}

36 37 38 39 40 41 42 43 44 45 46 47 48
#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;
    [self.forumTableView.mj_header beginRefreshing];
}

49 50 51 52
#pragma mark - 获取论坛项Type
- (void)getForumAllTypeAction
{
    WS(weakSelf);
53
    [XBLoadingView showHUDViewWithDefault];;
54
    [HTTP networkWithDictionaryRequestWithURL:[NSString stringWithFormat:SERVERREQUESTURL(FORUMCATEGORYS),self.typeId] withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
55
        
56
        [XBLoadingView hideHUDViewWithDefault];
57
        [weakSelf endRefreshingForTableView:weakSelf.forumTableView];
曹云霄's avatar
曹云霄 committed
58
        if (RESULT(returnValue)) {
曹云霄's avatar
曹云霄 committed
59
            weakSelf.category = [[ForumCategoryResponse alloc] initWithDictionary:RESPONSE(returnValue) error:nil];
曹云霄's avatar
曹云霄 committed
60
            [weakSelf.forumTableView reloadData];
61
        }else{
62
            [XBLoadingView showHUDViewWithText:returnValue[@"message"]];
63
        }
64
    } withFailureBlock:^(NSError *error) {
65
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
66 67 68 69 70 71 72
    }];
}

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

77 78
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
曹云霄's avatar
曹云霄 committed
79
    return self.category.categories.count;
80
}
81 82 83

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
曹云霄's avatar
曹云霄 committed
84
    ForumItemListViewController *itemListVc = [[[self class] getLearningCenterStoryboardClass] instantiateViewControllerWithIdentifier:@"ForumItemListViewController"];
85 86 87
    TOForumCategoryEntity *category = self.category.categories[indexPath.row];
    category.typeId = self.typeId;
    itemListVc.category = category;
曹云霄's avatar
曹云霄 committed
88
    [self.navigationController pushViewController:itemListVc animated:YES];
89 90
}

91 92

@end