美文网首页
精华->推荐标签

精华->推荐标签

作者: CaesarsTesla | 来源:发表于2016-04-27 18:37 被阅读34次
#import "XMGRecommendTagsViewController.h"
#import "XMGRecommendTag.h"
#import <AFNetworking.h>
#import <SVProgressHUD.h>
#import <MJExtension.h>
#import "XMGRecommendTagCell.h"

@interface XMGRecommendTagsViewController ()
/** 标签数据 */
@property (nonatomic, strong) NSArray *tags;
@end

static NSString * const XMGTagsId = @"tag";

@implementation XMGRecommendTagsViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  [self setupTableView];

  [self loadTags];
}

- (void)loadTags
{
[SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeBlack];

// 请求参数
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"a"] = @"tag_recommend";
params[@"action"] = @"sub";
params[@"c"] = @"topic";

// 发送请求
[[AFHTTPSessionManager manager] GET:@"http://api.budejie.com/api/api_open.php" parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
    
    self.tags = [XMGRecommendTag objectArrayWithKeyValuesArray:responseObject];
    [self.tableView reloadData];
    
    [SVProgressHUD dismiss];
} failure:^(NSURLSessionDataTask *task, NSError *error) {
    [SVProgressHUD showErrorWithStatus:@"加载标签数据失败!"];
}];
}

- (void)setupTableView
{
self.title = @"推荐标签";
[self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([XMGRecommendTagCell class]) bundle:nil] forCellReuseIdentifier:XMGTagsId];
self.tableView.rowHeight = 90;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.backgroundColor = XMGGlobalBg;
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.tags.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
XMGRecommendTagCell *cell = [tableView dequeueReusableCellWithIdentifier:XMGTagsId];

  cell.recommendTag = self.tags[indexPath.row];

  return cell;
}

@end

相关文章

网友评论

      本文标题:精华->推荐标签

      本文链接:https://www.haomeiwen.com/subject/epbcrttx.html