//
|
// NetworkTestPage.m
|
// BaseProject
|
//
|
// Created by WindShan on 2016/12/5.
|
// Copyright © 2016年 WindShan. All rights reserved.
|
//
|
|
#import "NetworkTestPage.h"
|
#import "MJChiBaoZiHeader.h"
|
#import "MJChiBaoZiFooter.h"
|
#import "NetworkSingleton.h"
|
#import "JZMerchantModel.h"
|
#import "JZMerchantCell.h"
|
#import "BAFPSLabel.h"
|
|
#define LATITUDE_DEFAULT 39.983497
|
#define LONGITUDE_DEFAULT 116.318042
|
|
@interface NetworkTestPage ()<UITableViewDelegate,UITableViewDataSource>
|
{
|
NSInteger _offset;
|
NSInteger _KindID;//分类查询ID,默认-1
|
NSMutableArray *_MerchantArray;
|
|
}
|
|
@end
|
|
@implementation NetworkTestPage
|
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
|
[self initData];
|
|
//tableview
|
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
|
|
self.tableView.delegate = self;
|
self.tableView.dataSource = self;
|
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
[self.view addSubview:self.tableView];
|
[self setUpTableView];
|
|
[BAFPSLabel showInWindow:[UIApplication sharedApplication].keyWindow];
|
|
|
}
|
|
- (void)didReceiveMemoryWarning {
|
[super didReceiveMemoryWarning];
|
// Dispose of any resources that can be recreated.
|
}
|
|
|
#pragma mark - custom function begin
|
|
-(void)setUpTableView{
|
//添加下拉的动画图片
|
// 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadNewData方法)
|
self.tableView.mj_header = [MJChiBaoZiHeader headerWithRefreshingTarget:self refreshingAction:@selector(getFirstPageData)];
|
|
// 马上进入刷新状态
|
[self.tableView.mj_header beginRefreshing];
|
|
|
// 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadMoreData方法)
|
self.tableView.mj_footer = [MJChiBaoZiFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
|
|
}
|
|
|
-(void)initData
|
{
|
_MerchantArray = [[NSMutableArray alloc] init];
|
|
_offset = 0;
|
_KindID = -1;//默认-1
|
}
|
|
-(void)getFirstPageData{
|
_offset = 0;
|
[self refreshData];
|
}
|
|
-(void)refreshData{
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
[self getMerchantList];
|
});
|
}
|
|
-(void)loadMoreData{
|
NSLog(@"2222 offset:%zd",_offset);
|
_offset = _offset + 20;
|
NSLog(@"3333 offset:%zd",_offset);
|
[self refreshData];
|
}
|
|
//获取商家列表
|
-(void)getMerchantList
|
{
|
NSString *str = @"%2C";
|
|
NSString *hostStr = @"group/v1/poi/select/cate/";
|
NSString *paramsStr = @"?__skck=40aaaf01c2fc4801b9c059efcd7aa146&__skcy=WOdaAXJTFxIjDdjmt1z%2FJRzB6Y0%3D&__skno=91D0095F-156B-4392-902A-A20975EB9696&__skts=1436408836.151516&__skua=bd6b6e8eadfad15571a15c3b9ef9199a&__vhost=api.mobile.meituan.com&areaId=-1&ci=1&cityId=1&client=iphone&coupon=all&limit=20&movieBundleVersion=100&msid=48E2B810-805D-4821-9CDD-D5C9E01BC98A2015-07-09-09-42570&mypos=";
|
|
NSString *str1 = [NSString stringWithFormat:@"%@%ld%@",hostStr,(long)_KindID,paramsStr];
|
|
NSString *str2 = @"&sort=smart&userid=10086&utm_campaign=AgroupBgroupD100Fa20141120nanning__m1__leftflow___ab_pindaochangsha__a__leftflow___ab_gxtest__gd__leftflow___ab_gxhceshi__nostrategy__leftflow___ab_i550poi_ktv__d__j___ab_chunceshishuju__a__a___ab_gxh_82__nostrategy__leftflow___ab_i_group_5_3_poidetaildeallist__a__b___b1junglehomepagecatesort__b__leftflow___ab_gxhceshi0202__b__a___ab_pindaoshenyang__a__leftflow___ab_pindaoquxincelue0630__b__b1___ab_i_group_5_6_searchkuang__a__leftflow___i_group_5_2_deallist_poitype__d__d___ab_i550poi_xxyl__b__leftflow___ab_b_food_57_purepoilist_extinfo__a__a___ab_waimaiwending__a__a___ab_waimaizhanshi__b__b1___ab_i550poi_lr__d__leftflow___ab_i_group_5_5_onsite__b__b___ab_xinkeceshi__b__leftflowGmerchant&utm_content=4B8C0B46F5B0527D55EA292904FD7E12E48FB7BEA8DF50BFE7828AF7F20BB08D&utm_medium=iphone&utm_source=AppStore&utm_term=5.7&uuid=4B8C0B46F5B0527D55EA292904FD7E12E48FB7BEA8DF50BFE7828AF7F20BB08D&version_name=5.7";
|
|
|
NSString *urlStr = [NSString stringWithFormat:@"%@%f%@%f&offset=%zd%@",str1, LATITUDE_DEFAULT, str, LONGITUDE_DEFAULT, _offset,str2];
|
|
__weak __typeof(self) weakself = self;
|
|
// +(void)networkingPostMethod:(NSDictionary *)parameters urlName:(NSString *)urlName success:(SuccessBlock)successBlock failure:(FailureBlock)failureBlock
|
NSString *path = [[NSString alloc] initWithFormat:@"user/login"];
|
NSMutableDictionary *param = [[NSMutableDictionary alloc] init];
|
[param setValue:@"13999999999" forKey:@"userName"];
|
[param setValue:@"888888" forKey:@"password"];
|
|
[NetworkSingleton networkingPostMethod:param urlName:path success:^(id responseBody)
|
{
|
BaseResModel * model = [Global toBaseModel:responseBody];
|
|
|
NSLog(@"获取商家列表成功");
|
NSMutableArray *dataArray = [responseBody objectForKey:@"data"];
|
NSLog(@"%ld",dataArray.count);
|
NSLog(@"offset:%ld",_offset);
|
if (_offset == 0) {
|
NSLog(@"0000");
|
[_MerchantArray removeAllObjects];
|
}
|
|
for (int i = 0; i < dataArray.count; i++) {
|
JZMerchantModel *JZMerM = [JZMerchantModel mj_objectWithKeyValues:dataArray[i]];
|
[_MerchantArray addObject:JZMerM];
|
}
|
|
[weakself.tableView reloadData];
|
|
if (_offset == 0 && dataArray.count!=0) {
|
[weakself.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
|
}
|
|
// 拿到当前的上拉刷新控件,结束刷新状态
|
[weakself.tableView.mj_header endRefreshing];
|
[weakself.tableView.mj_footer endRefreshing];
|
|
}
|
failure:^(NSString *error)
|
{
|
NSLog(@"获取商家列表失败:%@",error);
|
[weakself.tableView.mj_header endRefreshing];
|
[weakself.tableView.mj_footer endRefreshing];
|
}];
|
|
}
|
|
#pragma mark 加载最后一份数据
|
- (void)loadLastData
|
{
|
// // 1.添加假数据
|
// for (int i = 0; i<5; i++) {
|
// [self.data addObject:MJRandomData];
|
// }
|
//
|
// // 2.模拟2秒后刷新表格UI(真实开发中,可以移除这段gcd代码)
|
// __weak UITableView *tableView = self.tableView;
|
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(MJDuration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
// // 刷新表格
|
// [tableView reloadData];
|
//
|
// // 拿到当前的上拉刷新控件,变为没有更多数据的状态
|
// [tableView.mj_footer endRefreshingWithNoMoreData];
|
// });
|
}
|
|
//获取当前位置信息
|
-(void)OnRefreshLocationBtn:(UIButton *)sender
|
{
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
//[self getPresentLocation];
|
});
|
}
|
|
#pragma mark - custom function end
|
|
#pragma mark - UITableViewDataSource
|
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
|
return 1;
|
}
|
|
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
return _MerchantArray.count;
|
}
|
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
|
return 92;
|
}
|
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
|
return 32;
|
}
|
|
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
|
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
|
headerView.backgroundColor = RgbColor(240, 239, 237);
|
|
//
|
UILabel *locationLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, SCREEN_WIDTH-10-40, 30)];
|
locationLabel.font = [UIFont systemFontOfSize:13];
|
// locationLabel.text = @"当前:海淀区中关村大街";
|
locationLabel.text = [NSString stringWithFormat:@"当前位置:昆山周市镇东辉路"];
|
locationLabel.textColor = [UIColor lightGrayColor];
|
[headerView addSubview:locationLabel];
|
|
//
|
UIButton *refreshBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
refreshBtn.frame = CGRectMake(SCREEN_WIDTH-30, 5, 20, 20);
|
[refreshBtn setImage:[UIImage imageNamed:@"icon_dellist_locate_refresh"] forState:UIControlStateNormal];
|
[refreshBtn addTarget:self action:@selector(OnRefreshLocationBtn:) forControlEvents:UIControlEventTouchUpInside];
|
[headerView addSubview:refreshBtn];
|
return headerView;
|
}
|
|
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
|
{
|
if ([cell respondsToSelector:@selector(setSeparatorInset:)])
|
{
|
[cell setSeparatorInset:UIEdgeInsetsZero];
|
}
|
if ([cell respondsToSelector:@selector(setLayoutMargins:)])
|
{
|
[cell setLayoutMargins:UIEdgeInsetsZero];
|
}
|
|
/*! 第一种:3d xyz三维坐标刚出现0.1 0.1 1 0.5 s后正常 */
|
// cell.layer.transform = CATransform3DMakeScale(0.1,0.1,1);
|
// [UIView animateWithDuration:0.6 animations:^{
|
//
|
// cell.layer.transform = CATransform3DMakeScale(1,1,1);
|
//
|
// }];
|
|
/*! 第二种:卡片式动画 */
|
// static CGFloat initialDelay = 0.2f;
|
// static CGFloat stutter = 0.06f;
|
//
|
// cell.contentView.transform = CGAffineTransformMakeTranslation(SCREEN_WIDTH, 0);
|
//
|
// [UIView animateWithDuration:1.0f delay:initialDelay + ((indexPath.row) * stutter) usingSpringWithDamping:0.6 initialSpringVelocity:0 options:0 animations:^{
|
// cell.contentView.transform = CGAffineTransformIdentity;
|
// } completion:NULL];
|
|
/*! 第三种:从下往上 */
|
|
// [UIView animateWithDuration:1 animations:^{
|
//
|
// cell.layer.transform = CATransform3DMakeTranslation(0, 0, 0);
|
//
|
// }];
|
|
/*! 第四种:右下角出来 */
|
|
// cell.layer.transform = CATransform3DMakeTranslation(SCREEN_WIDTH, SCREEN_HEIGHT, 0);
|
//
|
// [UIView animateWithDuration:0.5 animations:^{
|
//
|
// cell.layer.transform = CATransform3DMakeTranslation(0, 0, 0);
|
//
|
// }];
|
|
/*! 第五种:右上角出现 */
|
|
// cell.layer.transform = CATransform3DMakeTranslation(SCREEN_WIDTH, -SCREEN_HEIGHT, 0);
|
|
/*! 第六种:翻转动画 */
|
// CATransform3D rotation;
|
// rotation = CATransform3DMakeRotation( (90.0*M_PI)/180, 0.0, 0.7, 0.4);
|
// rotation.m44 = 1.0/ -600;
|
// //阴影
|
// cell.layer.shadowColor = [[UIColor blackColor]CGColor];
|
//
|
// //阴影偏移
|
// cell.layer.shadowOffset = CGSizeMake(10, 10);
|
// cell.alpha = 0;
|
// cell.layer.transform = rotation;
|
// //锚点
|
// cell.layer.anchorPoint = CGPointMake(0.5, 0.5);
|
// [UIView beginAnimations:@"rotation" context:NULL];
|
// [UIView setAnimationDuration:0.8];
|
// cell.layer.transform = CATransform3DIdentity;
|
// cell.alpha = 1;
|
// cell.layer.shadowOffset = CGSizeMake(0, 0);
|
// [UIView commitAnimations];
|
|
/*! 第七种:扇形动画 */
|
NSArray *array = tableView.indexPathsForVisibleRows;
|
|
NSIndexPath *firstIndexPath = array[0];
|
//设置anchorPoint
|
cell.layer.anchorPoint = CGPointMake(0, 0.5);
|
|
//为了防止cell视图移动,重新把cell放回原来的位置
|
cell.layer.position = CGPointMake(0, cell.layer.position.y);
|
//设置cell 按照z轴旋转90度,注意是弧度
|
if (firstIndexPath.row < indexPath.row)
|
{
|
cell.layer.transform = CATransform3DMakeRotation(M_PI_2, 0, 0, 1.0);
|
}
|
else
|
{
|
cell.layer.transform = CATransform3DMakeRotation(- M_PI_2, 0, 0, 1.0);
|
}
|
cell.alpha = 0.0;
|
[UIView animateWithDuration:1 animations:^{
|
|
cell.layer.transform = CATransform3DIdentity;
|
|
cell.alpha = 1.0;
|
|
}];
|
}
|
|
|
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
static NSString *cellIndentifier = @"merchantCell";
|
JZMerchantCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
|
if (cell == nil) {
|
cell = [[JZMerchantCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier];
|
}
|
|
JZMerchantModel *jzMerM = _MerchantArray[indexPath.row];
|
cell.jzMerM = jzMerM;
|
// [cell setJzMerM:jzMerM];//都行
|
|
return cell;
|
}
|
|
#pragma mark - UITableViewDelegate
|
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
{
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
JZMerchantModel *jzMerM = _MerchantArray[indexPath.row];
|
NSLog(@"poiid:%@",jzMerM.poiid);
|
|
// JZMerchantDetailViewController *jzMerchantDVC = [[JZMerchantDetailViewController alloc] init];
|
// jzMerchantDVC.poiid = jzMerM.poiid;
|
// [self.navigationController pushViewController:jzMerchantDVC animated:YES];
|
|
}
|
|
//动画-由大变小
|
-(void)zoomOut:(UIView *)view andAnimationDuration:(float)duration andWait:(BOOL)wait{
|
__block BOOL done = wait;
|
view.transform = CGAffineTransformIdentity;
|
[UIView animateWithDuration:duration animations:^{
|
view.transform = CGAffineTransformMakeScale(0, 0);
|
} completion:^(BOOL finished){
|
done = YES;
|
}];
|
|
while (done == NO) {
|
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
|
}
|
}
|
|
//动画-由小变大
|
-(void)zoomIn:(UIView *)view andAnimationDuration:(float)duration andWait:(BOOL)wait{
|
__block BOOL done = wait;
|
// view.transform = CGAffineTransformIdentity;
|
view.transform = CGAffineTransformMakeScale(0, 0);
|
[UIView animateWithDuration:duration animations:^{
|
// view.transform = CGAffineTransformMakeScale(0, 0);
|
view.transform = CGAffineTransformIdentity;
|
} completion:^(BOOL finished){
|
done = YES;
|
}];
|
|
while (done == NO) {
|
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
|
}
|
}
|
|
|
/*
|
#pragma mark - Navigation
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
// Get the new view controller using [segue destinationViewController].
|
// Pass the selected object to the new view controller.
|
}
|
*/
|
|
@end
|