1 #import "ViewController.h"
2 #import "TuanGouModel.h"
3 #import "TuanGouTableViewCell.h"
4 #define kDeviceWidth [UIScreen mainScreen].bounds.size.width
5 #define kDeviceHeight [UIScreen mainScreen].bounds.size.height
6 @interface ViewController ()<UITableViewDelegate,UITableViewDataSource,UISearchResultsUpdating>
7 {
8 UISearchController * _sscller;
9 }
10 @property(nonatomic,strong)NSMutableArray* secArrM;
11
12 @property(nonatomic,strong) NSMutableArray* tuanGouArrM;
13
14 @property(nonatomic,strong)UITableView* myTable;
15
16 @end
17
18 @implementation ViewController
19
20 - (void)viewDidLoad {
21
22 [super viewDidLoad];
23 [self createNa];
24 self.myTable.backgroundColor = [UIColor lightGrayColor];
25 [self createsecB];
26 [self setupRefresh];
27
28 self.title = @"美食家";
29 }
30
31 #pragma mark - 导航
32 -(void)createNa{
33
34 UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithTitle:@"Edit" style:UIBarButtonItemStylePlain target:self action:@selector(tableEdit:)];
35 self.navigationItem.rightBarButtonItem = rightItem;
36 self.title = @"美食家";
37
38 }
39
40 // 点击导航右侧编辑按钮时,让表格可编辑
41 -(void)tableEdit:(UIBarButtonItem *) btnItem{
42
43 // if (self.myTable.editing == NO ) { // 没有处于编辑状态,导航按钮文字为“Edit”
44 // // 点击“编辑”文字,让表格处于编辑状态,并把按钮的文字修改为“Done"
45 // self.myTable.editing = YES;
46 //
47 // }else{
48 // // 编辑状态下,点击”Done"按钮,取消表格的编辑状态,修改导航按钮文字为"Edit"
49 // self.myTable.editing = NO;
50 // btnItem.title = @"Edit" ;
51 // self.navigationItem.rightBarButtonItems = @[btnItem];
52 // }
53
54 }
55
56 -(void)createsecB{
57 _sscller = [[UISearchController alloc]initWithSearchResultsController:nil];
58 _sscller.searchResultsUpdater = self;
59 self.myTable.tableHeaderView = _sscller.searchBar;
60
61
62 }
63 -(NSMutableArray *)secArrM{
64
65
66 if (_secArrM == nil) {
67 return _secArrM = [NSMutableArray array];
68
69 }else{
70 return _secArrM;
71 }
72
73
74
75 }
76
77 - (void)didReceiveMemoryWarning {
78
79 [super didReceiveMemoryWarning];
80
81 }
82 #pragma mark - 表格懒加载
83 -(UITableView *)myTable{
84 if (_myTable == nil) {
85 _myTable = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kDeviceWidth, kDeviceHeight) style:UITableViewStylePlain];
86 [self.view addSubview:_myTable];
87
88 _myTable.delegate = self;
89 _myTable.dataSource = self;
90 _myTable .separatorStyle = UITableViewCellSeparatorStyleSingleLineEtched;
91
92 }
93 return _myTable;
94
95 }
96
97 #pragma mark - 团购数据懒加载
98 -(NSMutableArray *)tuanGouArrM{
99
100 if (_tuanGouArrM == nil) {
101 _tuanGouArrM = [NSMutableArray array];
102 NSString* plistPath = [[NSBundle mainBundle]pathForResource:@"tgs.plist" ofType:nil];
103 NSArray* tuanArr = [NSArray arrayWithContentsOfFile:plistPath];
104
105 for (NSDictionary* dict in tuanArr) {
106 TuanGouModel* model =[[TuanGouModel alloc]initWithDict:dict];
107 [_tuanGouArrM addObject:model];
108 }
109 }
110 return _tuanGouArrM;
111 }
112
113 #pragma mark - 数据源协议
114 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
115 if ( _sscll