请求结果简单显示:
用到的点评封装的类:
使用tableView简单展示:
// // DealListController.m // 帅哥_团购 // // Created by beyond on 14-8-14. // Copyright (c) 2014年 com.beyond. All rights reserved. // 点击dock上面的【团购】按钮对应的控制器,上面是导航栏,导航栏右边是searchBar,导航栏左边是一个大按钮(TopMenu)(内部由三个小按钮组成<TopMenuItem>) #import "DealListController.h" // 导航栏左边是一个大按钮(顶部菜单) #import "TopMenu.h" #import "DPAPI.h" #import "MetaDataTool.h" #import "Deal.h" #import "City.h" @interface DealListController ()<DPRequestDelegate> { // 用于保存服务器返回的所有deals字典,并转成一个个deal对象 NSMutableArray *_deals; } @end @implementation DealListController - (void)viewDidLoad { [super viewDidLoad]; // 1,设置上方的导航栏,右边是搜索bar,左边是一个大的VIEW(内有三个按钮) [self addNaviBarBtn]; _deals = [NSMutableArray array]; } // 1,设置上方的导航栏,右边是搜索bar,左边是一个大的VIEW(内有三个按钮) - (void)addNaviBarBtn { // 1.监听城市改变的通知 kAddAllNotes(dataChange) // 2.右边的搜索框 UISearchBar *s = [[UISearchBar alloc] init]; s.frame = CGRectMake(0, 0, 210, 35); s.placeholder = @"请输入商品名、地址等"; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:s]; // 3.左边的菜单栏,导航栏左边是一个大按钮(顶部菜单) TopMenu *topMenu = [[TopMenu alloc] init]; // 4.用于点击顶部按钮时,容纳创建出来的底部弹出菜单(包括一个contentView和cover,contentView又包括scrollView和subTitleImgView),本成员是由创建此TopMenu的外部赋值传入, 这里是控制器的view,就是导航栏下面的所有区域 topMenu.controllerView = self.view; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:topMenu]; } // temp -- test - (void)dataChange { DPAPI *dpapi = [[DPAPI alloc]init]; log(@"currentCity---%@",[MetaDataTool sharedMetaDataTool].currentCity); [dpapi requestWithURL:@"v1/deal/find_deals" params:@{@"city": [MetaDataTool sharedMetaDataTool].currentCity.name} delegate:self]; } // temp -- test - (void)request:(DPRequest *)request didFinishLoadingWithResult:(id)result { [_deals removeAllObjects]; NSArray *arr = result[@"deals"]; for (NSDictionary *dict in arr) { Deal *deal = [[Deal alloc]init]; [deal setValuesWithDict:dict]; [_deals addObject:deal]; // 接下来就可以给tableView提供数据源了 } log(@"--_deals--%@",_deals); [self.tableView reloadData]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { log(@"---------numberOfRowsInSection____deals.count %d",_deals.count); return _deals.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellID = @"Beyond"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; if (cell == nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID]; } // 设置cell中独一无二的内容 Deal *deal = [_deals objectAtIndex:indexPath.row]; cell.textLabel.text = deal.title; // cell.imageView.image = [UIImage imageNamed:deal.s_image_url]; cell.detailTextLabel.text = deal.desc; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; // 返回cell log(@"--cellForRowAtIndexPath---%@",cell.textLabel.text); return cell; } @end
iOS_21团购_发送请求获取【点评】数据,布布扣,bubuko.com
原文地址:http://blog.csdn.net/pre_eminent/article/details/38657881