-
首先创建一个Header File , 在其中写入URL
前两段代码为格式,因为URL开头的格式都是以前两段代码为开始,所以写入之后以后直接输入#define+URL
就可以了。
#define IP @"http://dalianmohekeji.eicp.net:8102/repastmanage"
#define URL(api) [ NSString stringWithFormat:@"%@%@",IP,api]
#define ******* (输入URL)@"/clientAPI/searchRestaurantList.json"
-(void)getData{
// //cityId:城市ID
// //lat:纬度
// //lng:经度
//showType
//sendPrice
// defaultOeder
//实例化一个字典
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
// 在字典中写入key
NSDictionary *userInfo = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserInfo"];
//向dic中传值
[dic setValue:userInfo[@"supermaketName"] forKey:@"supermaketName"];
[dic setValue:userInfo[@"tasteCategory"] forKey:@"tasteCategory"];
[dic setValue:@"0411" forKey:@"ctiyId"];
[dic setValue:[NSNumber numberWithDouble:121.517977] forKey:@"lng"];
[dic setValue:[NSNumber numberWithDouble:38.8496481] forKey:@"lat"];
[dic setValue:userInfo[@"type"] forKey:@"type"];
[dic setValue:@"1" forKey:@"showType"];
[MBProgressHUD showHUDAddedTo:self.view animated:YES];// 提示用户正在请求
[[SetRequest sharedInstance]postRequestWithURL:URL(*********输入URL)
postParems:dic content:^(NetWorkModel *model){
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
if(model.error){
NSLog(@"获取列表失败");
}else{
if ([model.responseDic[@"error_code"] intValue] == 0) {
_dataSource = model.responseDic[@"restaurantList"];
[_tableView reloadData];
}
}
}];
}
网友评论