结果表明,一个简单的请求:
用到的点评封装的类:
使用tableView简单展示:
// // DealListController.m // 帅哥_团购 // // Created by beyond on 14-8-14. // Copyright (c) 2014年 com.beyond. All rights reserved. // 点击dock上面的【团购】button相应的控制器,上面是导航栏,导航栏右边是searchBar,导航栏左边是一个大button(TopMenu)(内部由三个小button组成<TopMenuItem>) #import "DealListController.h" // 导航栏左边是一个大button(顶部菜单) #import "TopMenu.h" #import "DPAPI.h" #import "MetaDataTool.h" // 数据模型,相应server返回的一个团购字典 #import "Deal.h" // 数据模型,里面有一个数组,存放全部商区(District)对象 #import "City.h" @interface DealListController ()<DPRequestDelegate> { // 用于保存server返回的全部deals字典,并转成一个个deal对象 NSMutableArray *_deals; } @end @implementation DealListController - (void)viewDidLoad { [super viewDidLoad]; // 1,设置上方的导航栏,右边是搜索bar,左边是一个大的VIEW(内有三个button) [self addNaviBarBtn]; _deals = [NSMutableArray array]; } // 1,设置上方的导航栏,右边是搜索bar,左边是一个大的VIEW(内有三个button) - (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.左边的菜单条,导航栏左边是一个大button(顶部菜单) TopMenu *topMenu = [[TopMenu alloc] init]; // 4.用于点击顶部button时,容纳创建出来的底部弹出菜单(包含一个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]; [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提供数据源了 [self.tableView reloadData]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 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.detailTextLabel.text = deal.desc; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; // 返回cell return cell; } @end
版权声明:本文博客原创文章,博客,未经同意,不得转载。
原文:http://www.cnblogs.com/bhlsheji/p/4658657.html