精华->推荐标签

#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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容