-
首先創建一個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];
}
}
}];
}