269 lines
9.5 KiB
Objective-C
269 lines
9.5 KiB
Objective-C
//
|
|
// MoreBrandController.m
|
|
// Ifish
|
|
//
|
|
// Created by imac on 15/10/2.
|
|
// Copyright © 2015年 imac. All rights reserved.
|
|
//
|
|
|
|
#import "MoreBrandController.h"
|
|
#import "MyFishTankCell.h"
|
|
#import "FishTankModel.h"
|
|
#import "AFNetworking.h"
|
|
#import "JHRefresh.h"
|
|
#import "BrandCell.h"
|
|
#import "BrandModel.h"
|
|
#import "BrandDetailViewController.h"
|
|
|
|
#import "UIImageView+WebCache.h"
|
|
@interface MoreBrandController ()
|
|
{
|
|
BOOL _isRefreshing;
|
|
BOOL _isLoadMore;
|
|
|
|
}
|
|
@property(nonatomic)BOOL isRefreshing;
|
|
@property(nonatomic)BOOL isLoadMore;
|
|
//@property(nonatomic) NSInteger start;
|
|
@property(nonatomic,strong)NSMutableDictionary*para;
|
|
@property(nonatomic,copy)NSString* total;
|
|
@property(nonatomic) int page;
|
|
@end
|
|
|
|
@implementation MoreBrandController
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
|
|
[self addTitleViewWithTitle:@"更多品牌"];
|
|
[self getbrandData];
|
|
self.brandArr=[[NSMutableArray alloc]init];
|
|
[self.tableView registerNib:[UINib nibWithNibName:@"BrandCell" bundle:nil] forCellReuseIdentifier:@"BrandCell"];
|
|
[self creatReatRefreshView];
|
|
_para=[NSMutableDictionary dictionary];
|
|
|
|
}
|
|
-(void)getbrandData{
|
|
AFHTTPRequestOperationManager*mannager=[AFHTTPRequestOperationManager manager];
|
|
mannager.responseSerializer=[AFHTTPResponseSerializer serializer];
|
|
NSMutableDictionary * para = [NSMutableDictionary dictionary];
|
|
[para setValue:@"0" forKey:@"firstResult"];
|
|
[para setValue:@"10" forKey:@"pageSize"];
|
|
__weak typeof (self)weakSelf=self;
|
|
[mannager POST:kMoreBrandUrl parameters:para success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
|
if (responseObject) {
|
|
NSDictionary*dict=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
|
|
|
|
NSArray*dataArr=dict[@"data"];
|
|
NSLog(@"dic%@",dict);
|
|
|
|
for (NSDictionary*dictData in dataArr) {
|
|
// [self showTitle:@"" messsage:@"请求成功"];
|
|
BrandModel*model=[[BrandModel alloc]init];
|
|
model.venderId=dictData[@"venderId"];
|
|
model.brandName=dictData[@"brandName"];
|
|
model.brandIntroduce=dictData[@"brandIntroduce"];
|
|
model.appShow=dictData[@"appShow"];
|
|
model.logo=dictData[@"logo"];
|
|
|
|
[weakSelf.brandArr addObject:model];
|
|
// venderModel*vModel=[[venderModel alloc]init];
|
|
// vModel.venderId=dictData[@"venderId"];
|
|
// vModel.brandName=dictData[@"brandName"];
|
|
// vModel.brandIntroduce=dictData[@"brandIntroduce"];
|
|
// vModel.appShow=dictData[@"appShow"];
|
|
// vModel.logo=dictData[@"logo"];
|
|
// [[DataCenter defaultDtacenter]setValue:vModel forKey:@"venderModel"];
|
|
|
|
|
|
|
|
}
|
|
[weakSelf.tableView reloadData];
|
|
|
|
}
|
|
|
|
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
|
[self showTitle:@"提醒" messsage:@"请求出错"];
|
|
}];
|
|
}
|
|
- (void)didReceiveMemoryWarning {
|
|
[super didReceiveMemoryWarning];
|
|
|
|
}
|
|
|
|
#pragma mark - Table view data source
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
|
|
|
return 1;
|
|
}
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
|
|
return self.brandArr.count;
|
|
}
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
/**
|
|
* 此处采用自定义cell 便于扩展
|
|
*/
|
|
BrandCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BrandCell"];
|
|
if (cell==nil) {
|
|
cell=[[BrandCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"BrandCell"];
|
|
}
|
|
|
|
|
|
BrandModel*model=self.brandArr[indexPath.row];
|
|
cell.brandName.text=model.brandName;
|
|
[cell.brandLogo sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kGetLogUrl,model.logo]] placeholderImage:[UIImage imageNamed:@"brandLogo_hold"]];
|
|
return cell;
|
|
}
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
|
return 50;
|
|
}
|
|
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
|
BrandDetailViewController*detailVC=[[BrandDetailViewController alloc]init];
|
|
BrandModel*verModel=self.brandArr[indexPath.row];
|
|
detailVC.model=verModel;
|
|
[self.navigationController pushViewController:detailVC animated:YES];
|
|
|
|
}
|
|
//-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
|
|
// UIView*footview=[[UIView alloc]init];
|
|
// footview.frame=CGRectMake(0, 0, kScreenSize.width, 100);
|
|
// return footview;
|
|
//}
|
|
-(void)showTitle:(NSString*)title messsage:(NSString*)message{
|
|
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:title message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
|
|
NSTimeInterval dismissSeconds=2.0;
|
|
[alert show];
|
|
[self performSelector:@selector(dismissAlert:) withObject:alert afterDelay:dismissSeconds];
|
|
// UIAlertController *alertContorller=[UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
|
|
// UIAlertAction*cancleAction=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
|
|
//
|
|
// UIAlertAction *sureAction=[UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:nil];
|
|
// [alertContorller addAction:cancleAction];
|
|
// [alertContorller addAction:sureAction];
|
|
// [self presentViewController:alertContorller animated:YES completion:nil];
|
|
|
|
|
|
|
|
}
|
|
-(void)dismissAlert:(UIAlertView*)alertView{
|
|
|
|
[alertView dismissWithClickedButtonIndex:[alertView cancelButtonIndex] animated:YES];
|
|
}
|
|
|
|
|
|
-(void)creatReatRefreshView{
|
|
__weak typeof (self)weskSelf=self;
|
|
// 下拉刷新
|
|
[weskSelf.tableView addRefreshHeaderViewWithAniViewClass:[JHRefreshCommonAniView class] beginRefresh:^{
|
|
if (weskSelf.isRefreshing) {
|
|
return ;
|
|
}
|
|
weskSelf.isRefreshing=YES;
|
|
_page=0;
|
|
[_para setValue:@"0" forKey:@"firstResult"];
|
|
[_para setValue:@"10" forKey:@"pageSize"];
|
|
[weskSelf addTaskWithUrl:kMoreBrandUrl isRefresh:YES];
|
|
[self.tableView reloadData];
|
|
|
|
}];
|
|
//上拉加载更多
|
|
[weskSelf.tableView addRefreshFooterViewWithAniViewClass:[JHRefreshCommonAniView class] beginRefresh:^{
|
|
if (weskSelf.isLoadMore) {
|
|
return ;
|
|
}
|
|
weskSelf.isLoadMore=YES;
|
|
|
|
NSInteger pagecount =[_total integerValue]/10+1;
|
|
if (_page<pagecount-1) {
|
|
_page++;
|
|
|
|
NSInteger first=(NSInteger)_page*10;
|
|
NSString*firsStr=[NSString stringWithFormat:@"%ld",(long)first];
|
|
// NSString*first=(NSString*)(_page*10+9);
|
|
[_para setValue:firsStr forKey:@"firstResult"];
|
|
[_para setValue:@"10" forKey:@"pageSize"];
|
|
NSString*url=kMoreBrandUrl;
|
|
[weskSelf addTaskWithUrl:url isRefresh:NO];
|
|
|
|
|
|
}else{
|
|
[self endRefreshing];
|
|
[self showTitle:@"" messsage:@"没有了"];
|
|
}
|
|
|
|
|
|
}];
|
|
|
|
|
|
}
|
|
-(void)endRefreshing{
|
|
if (self.isRefreshing) {
|
|
self.isRefreshing=NO;
|
|
[self.tableView headerEndRefreshingWithResult:JHRefreshResultNone];
|
|
}
|
|
if (self.isLoadMore) {
|
|
self.isLoadMore=NO;
|
|
[self.tableView footerEndRefreshing];
|
|
}
|
|
}
|
|
-(void)addTaskWithUrl:(NSString *)url isRefresh:(BOOL)isRefresh{
|
|
AFHTTPRequestOperationManager*mannager=[AFHTTPRequestOperationManager manager];
|
|
mannager.responseSerializer=[AFHTTPResponseSerializer serializer];
|
|
|
|
|
|
|
|
__weak typeof (self)weakSelf=self;
|
|
if (isRefresh) {
|
|
[weakSelf.brandArr removeAllObjects];
|
|
}
|
|
|
|
|
|
[mannager POST:kMoreBrandUrl parameters:_para success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
|
if (responseObject) {
|
|
NSDictionary*dict=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
|
|
|
|
NSArray*dataArr=dict[@"data"];
|
|
NSLog(@"dic%@",dict);
|
|
|
|
for (NSDictionary*dictData in dataArr) {
|
|
// [self showTitle:@"" messsage:@"请求成功"];
|
|
BrandModel*model=[[BrandModel alloc]init];
|
|
model.venderId=dictData[@"venderId"];
|
|
model.brandName=dictData[@"brandName"];
|
|
model.brandIntroduce=dictData[@"brandIntroduce"];
|
|
model.appShow=dictData[@"appShow"];
|
|
model.logo=dictData[@"logo"];
|
|
|
|
[weakSelf.brandArr addObject:model];
|
|
// venderModel*vModel=[[venderModel alloc]init];
|
|
// vModel.venderId=dictData[@"venderId"];
|
|
// vModel.brandName=dictData[@"brandName"];
|
|
// vModel.brandIntroduce=dictData[@"brandIntroduce"];
|
|
// vModel.appShow=dictData[@"appShow"];
|
|
// vModel.logo=dictData[@"logo"];
|
|
// [[DataCenter defaultDtacenter]setValue:vModel forKey:@"venderModel"];
|
|
|
|
|
|
|
|
}
|
|
[weakSelf.tableView reloadData];
|
|
[weakSelf endRefreshing];
|
|
}
|
|
|
|
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
|
[self showTitle:@"提醒" messsage:@"请求出错"];
|
|
[weakSelf endRefreshing];
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
@end
|