您的位置:首页 > 移动开发 > IOS开发

iOS_21团购_发送请求获取【点评】数据

2014-08-18 12:05 351 查看
请求结果简单显示:



用到的点评封装的类:





使用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"
// 数据模型,里面有一个数组,存放所有商区(District)对象
#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];

[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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iOS iPad 团购 服务器