具体实现功能与首页界面的功能相近,比其简单。
1.仍然需要在API接口代码中 添加解析方法
NSMutableArray*groupArr = [NSMutableArray array];
groupArr = [JsonParser jsonParserGroupBuyByDic:dic];
实现顺序: 1.创建模型,模型声明属性;
2.创建解析类,实现方法:(没有得到 API地址,没有得到Json之前不用实现具体代码 只需要一个方法名,有返回数组);
3.在API接口代码中 调用解析方法,声明数组,返回数组,
4.在团购主页面即viewController中调用第二个解析API接口方法:传递进去可变数组的判定; 声明当前页面的数据源数组接收 这个API接口方法返回的数组
[self.dic setObject:@"北京" forKey:@"city"];
self.groups = [DianpingApi requestDealsWithParams:self.dic]; 字典用之前要初始化。
5.得到数据源数组,就可以进行进一步操作了。 哈哈哈
6.自定义Cell 创建出来, 在自定义Cell界面关联控件, 声明对象来接收viewController中页面当前点击的Cell传递出去的
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
GroupBuyTableViewCell *cell = [[NSBundle mainBundle]loadNibNamed:@"GroupBuyTableViewCell" owner:self options:nil].lastObject;
if (!cell) {
cell = [[GroupBuyTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
cell.group = self.groups[indexPath.row]; 6中描述的就是这个
return cell;
}
7.就是跳转界面,这个最简单了 在didselect中 创建一个全屏的WebView将当前点击的行 对应传递跳转
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
UIViewController *vc = [[UIViewController alloc]init];
UIWebView *wv = [[UIWebView alloc]initWithFrame:vc.view.bounds];
[vc.view addSubview:wv];
self.g = self.groups[indexPath.row];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.g.deal_url]];
[wv loadRequest:request];
[self.navigationController pushViewController:vc animated:YES];
}
本文详细阐述了在API接口基础上实现团购页面功能的具体步骤,包括创建模型、解析JSON数据、调用API接口、处理数据源数组、自定义Cell界面及跳转界面等关键环节。

1万+

被折叠的 条评论
为什么被折叠?



