課程背景:
聚合數據是一家國內最大的基礎數據 API 提供商。免費提供從天氣查詢、空氣質量、地圖座標到金融基金、電商比價、違章查詢等各個領域的安全、穩定和高效的數據。開發者可以免費使用聚合數據 API 進行移動 App 的快速開發,免除數據收集、維護等環節,大大降低開發週期及成本。
核心內容:
1.條碼查詢器結構分析。
2.如何將聚合數據 SDK 添加到工程中。
3.模型以及業務類的封裝。
4.控制器間的數據傳遞。
5.tableView 以及 webView 的使用。
開發環境:Xcode 6、Mac OS X 10.10
課程大綱
1. 條碼查詢器界面搭建
本課時通過分析條碼查詢的UI結構和業務邏輯,快速的搭建起條碼查詢器的業務界面。
2. 聚合數據SDK使用介紹
本課時介紹聚合數據SDK的下載,以及通過 SDK 使用文檔和其中的 Demo,爲工程添加 framework,並通過申請聚合數據賬號,獲取工程需要的 openID 和請求參數。並通過測試代碼分析聚合數據的返回數據。
3. 城市選擇界面完善
本課時演示如何將第三方框架以及極客學院老師封裝好的業務類以及模型添加到工程中並快速使用,並將獲取的數據顯示在城市選擇界面,並實現城市選擇界面和首頁的數據傳遞。
4. 商品詳情界面初步完善
本課時分析商品詳情界面數據,演示如何使用已經封裝好的業務類和模型將電商和超市數據顯示到界面上,並給出聚合數據獲取數據類型不確定的解決方案。
5. 商品詳情界面完整數據展示
本課時演示如何添加組頭控件以及如何利用Xib快速創建一個 tableView 的 HeaderView ,並將服務器數據利用模型傳遞到 Xib 內的控件中,其中 imageView 的圖片顯示用到了 SDWebImage。
6. 購買界面完善
本課時演示如何將 UIViewController 中控制器的 view 換成 webView,並利用 webView 展示購買界面,並利用 MBProgressHUD 給出了電商無購買鏈接時候的UI提示。
課程原型圖
課程代碼片段
@interface ViewController () <JKCitiesControllerDelegate>
@property (nonatomic, copy) NSString *cityID;
@property (weak, nonatomic) IBOutlet UITextField *inputTextField;
@end
@implementation ViewController
- (IBAction)chaxunOnClick {
if (!self.inputTextField.hasText) {
[MBProgressHUD showError:@"請輸入商品條碼!"];
return;
}
JKGoodsController *gVC = [[JKGoodsController alloc] init];
BarCodeParam *param = [[BarCodeParam alloc] init];
param.cityid = self.cityID;
#warning 實際開發這裏傳入的是文本輸入看中的字符串
param.barcode = @"6923450601822";
//param.barcode = self.inputTextField.text;
gVC.barCodeParam = param;
[self.navigationController pushViewController:gVC animated:YES];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[JHOpenidSupplier shareSupplier] registerJuheAPIByOpenId:JHOpenID];
self.title = @"條碼查詢器";
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"上海" style:UIBarButtonItemStyleDone target:self action:@selector(openCitiesVC)];
self.cityID = @"1";
//
// [self test:kJHAPIS_EX_JHBAR_CITY parameters:@{ @"pname":@"com.jikexueyuan.JKJHBarCode" ,@"v":@"2.0"}];
[self test:kJHAPIS_EX_JHBAR_BAR parameters:@{ @"barcode": @"6923450601822" ,@"cityid":@"1" , @"pname":@"com.jikexueyuan.JKJHBarCode" ,@"v":@"2.0" }];
// [self test:kJHAPIS_EX_JHBAR_BUY parameters:@{ @"barcode":@"6923450601822" , @"dsid":@"5" ,@"pname":@"com.jikexueyuan.JKJHBarCode" ,@"v":@"2.0"}];
}
- (void)test:(NSString *)path parameters:(NSDictionary *)parameters{
JuheAPI *juheapi = [JuheAPI shareJuheApi];
[juheapi executeWorkWithAPI:path
parameters:parameters
success:^(id responseObject){
if ([[parameters objectForKey:@"dtype"] isEqualToString:@"xml"]) {
NSLog(@"***xml*** \n %@", responseObject);
}else{
int error_code = [[responseObject objectForKey:@"error_code"] intValue];
if (!error_code) {
NSLog(@" %@", responseObject);
}else{
NSLog(@" %@", responseObject);
}
}
} failure:^(NSError *error) {
NSLog(@"error: %@",error.description);
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)openCitiesVC
{
JKCitiesController *cVC = [[JKCitiesController alloc] init];
cVC.delegate = self;
[self.navigationController pushViewController:cVC animated:YES];
}
#pragma mark - JKCitiesControllerDelegate
- (void)backToMainVcWithCity:(City *)city
{
// 1.替換右上角中按鈕的 title
self.navigationItem.rightBarButtonItem.title = city.cityname;
// 2.傳遞給主控制器一個 cityid 的數據
self.cityID = [NSString stringWithFormat:@"%@", city.cityid];
}
課程地址:http://www.jikexueyuan.com/course/324.html