设为首页 加入收藏

TOP

UITableView与UISearchController搜索及上拉加载,下拉刷新(一)
2017-10-13 10:23:59 】 浏览:7351
Tags:UITableView UISearchController 搜索 加载 下拉 刷新
  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
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇cocoapod-使用cocoapod安装AFNetw.. 下一篇字典转模型之KVC

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目