-
Notifications
You must be signed in to change notification settings - Fork 126
/
CommodityTableViewController.m
executable file
·179 lines (139 loc) · 6.87 KB
/
CommodityTableViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//
// CommodityTableViewController.m
// jdmobile
//
// Created by SYETC02 on 15/6/19.
// Copyright (c) 2015年 SYETC02. All rights reserved.
//
#import "CommodityTableViewController.h"
#import "PPiFlatSegmentedControl.h"
#import "NSString+FontAwesome.h"
#import "SearchBarView.h"
#import "JDNavigationController.h"
#import "UIViewController+REFrostedViewController.h"
#import "CommodityModel.h"
#import "CommodityTableViewCell.h"
#import "DetailsViewController.h"
@interface CommodityTableViewController ()<SearchBarViewDelegate,UITableViewDataSource,UITableViewDelegate>
{
UITableView *_tableView;
NSMutableArray *_commodity;
}
@end
@implementation CommodityTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
//初始化数据
[self initData];
//设置导航栏
[self setupNavigationItem];
//初始化视图
[self initView];
}
#pragma mark 加载数据
-(void)initData{
NSString *path=[[NSBundle mainBundle] pathForResource:@"Commodity" ofType:@"plist"];
NSArray *array=[NSArray arrayWithContentsOfFile:path];
_commodity=[[NSMutableArray alloc]init];
[array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[_commodity addObject:[CommodityModel commodityWithDictionary:obj]];
}];
}
- (void)setupNavigationItem {
self.navigationItem.leftBarButtonItem = [UIBarButtonItem BarButtonItemWithBackgroudImageName:@"back_bt_7" highBackgroudImageName:nil target:self action:@selector(backClick)];
self.navigationItem.rightBarButtonItem = [UIBarButtonItem BarButtonItemWithBackgroudImageName:@"changeProductListGrid" highBackgroudImageName:nil target:self action:@selector(changeClick)];
//将搜索条放在一个UIView上
SearchBarView *searchView = [[SearchBarView alloc]initWithFrame:CGRectMake(0, 7, 240 , 30)];
searchView.delegate=self;
self.navigationItem.titleView = searchView;
self.navigationController.navigationBar.shadowImage=[[UIImage alloc]init];
}
- (void)initView{
PPiFlatSegmentedControl *segmented=[[PPiFlatSegmentedControl alloc]
initWithFrame:CGRectMake(0, 64, self.view.width, 40)
items:
@[@{@"text":@"综合",@"icon":@"icon-sort"},
@{@"text":@"销量"},
@{@"text":@"价格",@"icon":@"icon-sort"},
@{@"text":@"筛选",@"icon":@"icon-glass"}
]
iconPosition:IconPositionRight
andSelectionBlock:^(NSUInteger segmentIndex) {
switch (segmentIndex) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
[(JDNavigationController*)self.navigationController showRightMenu];
break;
default:
break;
}
}];
segmented.color=[UIColor colorWithPatternImage:[UIImage imageNamed:@"navigationbar_background"]];
segmented.borderColor=[UIColor darkGrayColor];
//segmented.selectedColor=[UIColor colorWithRed:0.0f/255.0 green:141.0f/255.0 blue:176.0f/255.0 alpha:1];
segmented.textAttributes=@{NSFontAttributeName:[UIFont systemFontOfSize:14],
NSForegroundColorAttributeName:JDColor(135, 127, 141)};
segmented.selectedTextAttributes=@{NSFontAttributeName:[UIFont systemFontOfSize:14],
NSForegroundColorAttributeName:JDColor(243, 106, 107)};
[self.view addSubview:segmented];
//创建一个分组样式的UITableView
_tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 104, self.view.width, self.view.height-104) style:UITableViewStylePlain];
//设置数据源,注意必须实现对应的UITableViewDataSource协议
_tableView.dataSource=self;
//设置代理
_tableView.delegate=self;
_tableView.rowHeight = 120;
_tableView.backgroundColor=JDColor(240, 243, 245);
[self.view addSubview:_tableView];
}
- (void)backClick{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)changeClick{
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - UITableViewDataSource数据源方法
//#pragma mark 返回分组数
//-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
// return 1;
//}
#pragma mark 返回每组行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _commodity.count;
}
#pragma mark返回每行的单元格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier=@"Cell";
CommodityTableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell==nil){
cell=[[NSBundle mainBundle] loadNibNamed:@"CommodityTableViewCell" owner:self options:nil][0];
}
CommodityModel *commodity =_commodity[indexPath.row];
cell.commodityImg.image=[UIImage imageNamed:commodity.commodityImageUrl];
cell.commodityName.text=commodity.commodityName;
cell.commodityPrice.text=[NSString stringWithFormat:@"¥%@",commodity.commodityPrice];
cell.commodityZX.image=[UIImage imageNamed:commodity.commodityZX];
cell.commodityPraise.text=commodity.praise;
return cell;
}
#pragma mark - UITableViewDelegate代理方法
#pragma mark 每行点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"cell selected at index path %i", (int)indexPath.row);
[tableView deselectRowAtIndexPath:indexPath animated:YES];
DetailsViewController * detailsTVC = [[DetailsViewController alloc]init];
[self.navigationController pushViewController:detailsTVC animated:YES];
}
#pragma mark 滑动事件
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
NSLog(@"scroll view did begin dragging");
}
@end