1010cc时时彩标准版 > 操作系统 > 1010cc时时彩标准版下拉刷新,uitableview下拉刷新

原标题:1010cc时时彩标准版下拉刷新,uitableview下拉刷新

浏览次数:79 时间:2019-08-11

UITableView与UISearchController搜索及上拉加载,下拉刷新,uitableview下拉刷新

  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 ( _sscller.active ) {        //搜索结果表格
116         return  self.secArrM.count;
117     }
118     
119     else{
120         return self.tuanGouArrM.count;
121 
122    }
123 }
124 
125 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
126  
127     //注册
128     [tableView registerClass:[TuanGouTableViewCell class] forCellReuseIdentifier:@"tuanCell"];
129     //重置
130     TuanGouTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"tuanCell"forIndexPath:indexPath];
131     cell.backgroundColor = [UIColor yellowColor];
132     // 选中风格
133     cell.selectionStyle = UITableViewCellSelectionStyleNone;
134     if( !_sscller.active ){
135        cell.tuanGouModel = self.tuanGouArrM[indexPath.row];
136     }else{          //搜索结果
137        cell.tuanGouModel = self.secArrM[indexPath.row];
138     }
139     
140 
141     return cell;
142 }
143 #pragma mark - TableV协议
144 
145 -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
146 
147     return 80;
148 }
149 
150 -(void)updateSearchResultsForSearchController:(UISearchController *)searchController{
151     
152     [self.secArrM removeAllObjects];
153         for (int j = 0; j < _tuanGouArrM.count; j  ) {
154             TuanGouModel* model =[[TuanGouModel alloc]init];
155                  model = _tuanGouArrM[j];
156             if ([model.title isEqualToString: _sscller.searchBar.text]) {
157                 [self.secArrM addObject: model];
158             }
159     }
160     
161     [self.myTable reloadData];
162 }
163 
164 
165 //允许Menu菜单
166 -(BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath
167 {
168     return   YES;
169 }
170 
171 //每个cell都可以点击出现Menu菜单
172 -(BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
173 {
174     return   YES;
175 
176 }
177 -(void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender{
178 
179     NSLog(@"长按");
180     
181     if (action ==@selector(copy:)) {
182         
183        NSLog(@"copy");
184         
185     }
186     if (action ==@selector(cut:)) {
187         NSLog(@"cut");
188         
189     }
190     
191     if (action ==@selector(paste:)) {
192         
193        
194         NSLog(@"paste");
195     }
196 
197     if (action ==@selector(selectAll:)) {
198         
199         
200         NSLog(@"selectAll");
201     }
202 
203 
204 }
205 //上拉加载
206 -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
207     if (indexPath.row == self.tuanGouArrM.count - 1) {
208         NSLog(@"最后一行");
209         
210         TuanGouModel* model =[[TuanGouModel alloc]init];
211         model = _tuanGouArrM[arc4random()];
212         [_tuanGouArrM addObject:model];
213         [self.myTable reloadData];
214 
215     }
216 }
217 
218 //下拉刷新
219 -(void)setupRefresh
220 {
221     //1.添加刷新控件
222     UIRefreshControl *control=[[UIRefreshControl alloc]init];
223     [control addTarget:self action:@selector(refreshStateChange:) forControlEvents:UIControlEventValueChanged];
224     [self.myTable addSubview:control];
225     
226     //2.马上进入刷新状态,并不会触发UIControlEventValueChanged事件
227     [control beginRefreshing];
228     
229     // 3.加载数据
230     [self refreshStateChange:control];
231 }
232 
233 
234 /**
235  *  UIRefreshControl进入刷新状态:加载最新的数据
236  */
237 -(void)refreshStateChange:(UIRefreshControl *)control
238 {
239     TuanGouModel* model =[[TuanGouModel alloc]init];
240     model = _tuanGouArrM[arc4random()];
241     [_tuanGouArrM insertObject:model atIndex:0];
242     [self.myTable reloadData];
243 
244      NSLog(@"第一行");
245      [control endRefreshing];
246     
247 }
248 
249 //指示是否允许高亮显示选中的行
250 - (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath{
251     
252     return YES;
253 }
254 
255 //选中某行时执行
256 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
257     NSLog(@"selected: %ld, row:%ld", indexPath.section, indexPath.row);
258 }
259 //取消选中时执行,这个方法常在表格允许多选时调用执行
260 - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
261     NSLog(@"Deselected: %ld, row:%ld", indexPath.section, indexPath.row);
262 }

源文件这里有

UITableView与UISearchController寻觅及上拉加载,下拉刷新

1 #import " ViewController.h " 2 #import " TuanGouModel.h " 3 #import " TuanGouTableV...

  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 ( _sscller.active ) {        //搜索结果表格
116         return  self.secArrM.count;
117     }
118     
119     else{
120         return self.tuanGouArrM.count;
121 
122    }
123 }
124 
125 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
126  
127     //注册
128     [tableView registerClass:[TuanGouTableViewCell class] forCellReuseIdentifier:@"tuanCell"];
129     //重置
130     TuanGouTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"tuanCell"forIndexPath:indexPath];
131     cell.backgroundColor = [UIColor yellowColor];
132     // 选中风格
133     cell.selectionStyle = UITableViewCellSelectionStyleNone;
134     if( !_sscller.active ){
135        cell.tuanGouModel = self.tuanGouArrM[indexPath.row];
136     }else{          //搜索结果
137        cell.tuanGouModel = self.secArrM[indexPath.row];
138     }
139     
140 
141     return cell;
142 }
143 #pragma mark - TableV协议
144 
145 -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
146 
147     return 80;
148 }
149 
150 -(void)updateSearchResultsForSearchController:(UISearchController *)searchController{
151     
152     [self.secArrM removeAllObjects];
153         for (int j = 0; j < _tuanGouArrM.count; j  ) {
154             TuanGouModel* model =[[TuanGouModel alloc]init];
155                  model = _tuanGouArrM[j];
156             if ([model.title isEqualToString: _sscller.searchBar.text]) {
157                 [self.secArrM addObject: model];
158             }
159     }
160     
161     [self.myTable reloadData];
162 }
163 
164 
165 //允许Menu菜单
166 -(BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath
167 {
168     return   YES;
169 }
170 
171 //每个cell都可以点击出现Menu菜单
172 -(BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
173 {
174     return   YES;
175 
176 }
177 -(void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender{
178 
179     NSLog(@"长按");
180     
181     if (action ==@selector(copy:)) {
182         
183        NSLog(@"copy");
184         
185     }
186     if (action ==@selector(cut:)) {
187         NSLog(@"cut");
188         
189     }
190     
191     if (action ==@selector(paste:)) {
192         
193        
194         NSLog(@"paste");
195     }
196 
197     if (action ==@selector(selectAll:)) {
198         
199         
200         NSLog(@"selectAll");
201     }
202 
203 
204 }
205 //上拉加载
206 -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
207     if (indexPath.row == self.tuanGouArrM.count - 1) {
208         NSLog(@"最后一行");
209         
210         TuanGouModel* model =[[TuanGouModel alloc]init];
211         model = _tuanGouArrM[arc4random()];
212         [_tuanGouArrM addObject:model];
213         [self.myTable reloadData];
214 
215     }
216 }
217 
218 //下拉刷新
219 -(void)setupRefresh
220 {
221     //1.添加刷新控件
222     UIRefreshControl *control=[[UIRefreshControl alloc]init];
223     [control addTarget:self action:@selector(refreshStateChange:) forControlEvents:UIControlEventValueChanged];
224     [self.myTable addSubview:control];
225     
226     //2.马上进入刷新状态,并不会触发UIControlEventValueChanged事件
227     [control beginRefreshing];
228     
229     // 3.加载数据
230     [self refreshStateChange:control];
231 }
232 
233 
234 /**
235  *  UIRefreshControl进入刷新状态:加载最新的数据
236  */
237 -(void)refreshStateChange:(UIRefreshControl *)control
238 {
239     TuanGouModel* model =[[TuanGouModel alloc]init];
240     model = _tuanGouArrM[arc4random()];
241     [_tuanGouArrM insertObject:model atIndex:0];
242     [self.myTable reloadData];
243 
244      NSLog(@"第一行");
245      [control endRefreshing];
246     
247 }
248 
249 //指示是否允许高亮显示选中的行
250 - (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath{
251     
252     return YES;
253 }
254 
255 //选中某行时执行
256 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
257     NSLog(@"selected: %ld, row:%ld", indexPath.section, indexPath.row);
258 }
259 //取消选中时执行,这个方法常在表格允许多选时调用执行
260 - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
261     NSLog(@"Deselected: %ld, row:%ld", indexPath.section, indexPath.row);
262 }

UITableView与UISearchController搜索及上拉加载,下拉刷新

//定义下拉回调函数RefreshHeader * refreshHeader =[[RefreshHeader alloc]initWithTarget:self refreshSelector:@selector(gobackMessage)];self.tableView.refreshHeader =refreshHeader;//设置刷新类型,枚举值,自定义self.tableView.type =FLRefreshTypeAll;

5

UITableView与UISearchController搜索及上拉加载,下拉刷新

源文件这里有

福寿双全上拉的自发性加载。

69

源文件这里有

  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 ( _sscller.active ) {        //搜索结果表格
116         return  self.secArrM.count;
117     }
118     
119     else{
120         return self.tuanGouArrM.count;
121 
122    }
123 }
124 
125 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
126  
127     //注册
128     [tableView registerClass:[TuanGouTableViewCell class] forCellReuseIdentifier:@"tuanCell"];
129     //重置
130     TuanGouTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"tuanCell"forIndexPath:indexPath];
131     cell.backgroundColor = [UIColor yellowColor];
132     // 选中风格
133     cell.selectionStyle = UITableViewCellSelectionStyleNone;
134     if( !_sscller.active ){
135        cell.tuanGouModel = self.tuanGouArrM[indexPath.row];
136     }else{          //搜索结果
137        cell.tuanGouModel = self.secArrM[indexPath.row];
138     }
139     
140 
141     return cell;
142 }
143 #pragma mark - TableV协议
144 
145 -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
146 
147     return 80;
148 }
149 
150 -(void)updateSearchResultsForSearchController:(UISearchController *)searchController{
151     
152     [self.secArrM removeAllObjects];
153         for (int j = 0; j < _tuanGouArrM.count; j  ) {
154             TuanGouModel* model =[[TuanGouModel alloc]init];
155                  model = _tuanGouArrM[j];
156             if ([model.title isEqualToString: _sscller.searchBar.text]) {
157                 [self.secArrM addObject: model];
158             }
159     }
160     
161     [self.myTable reloadData];
162 }
163 
164 
165 //允许Menu菜单
166 -(BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath
167 {
168     return   YES;
169 }
170 
171 //每个cell都可以点击出现Menu菜单
172 -(BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
173 {
174     return   YES;
175 
176 }
177 -(void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender{
178 
179     NSLog(@"长按");
180     
181     if (action ==@selector(copy:)) {
182         
183        NSLog(@"copy");
184         
185     }
186     if (action ==@selector(cut:)) {
187         NSLog(@"cut");
188         
189     }
190     
191     if (action ==@selector(paste:)) {
192         
193        
194         NSLog(@"paste");
195     }
196 
197     if (action ==@selector(selectAll:)) {
198         
199         
200         NSLog(@"selectAll");
201     }
202 
203 
204 }
205 //上拉加载
206 -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
207     if (indexPath.row == self.tuanGouArrM.count - 1) {
208         NSLog(@"最后一行");
209         
210         TuanGouModel* model =[[TuanGouModel alloc]init];
211         model = _tuanGouArrM[arc4random()];
212         [_tuanGouArrM addObject:model];
213         [self.myTable reloadData];
214 
215     }
216 }
217 
218 //下拉刷新
219 -(void)setupRefresh
220 {
221     //1.添加刷新控件
222     UIRefreshControl *control=[[UIRefreshControl alloc]init];
223     [control addTarget:self action:@selector(refreshStateChange:) forControlEvents:UIControlEventValueChanged];
224     [self.myTable addSubview:control];
225     
226     //2.马上进入刷新状态,并不会触发UIControlEventValueChanged事件
227     [control beginRefreshing];
228     
229     // 3.加载数据
230     [self refreshStateChange:control];
231 }
232 
233 
234 /**
235  *  UIRefreshControl进入刷新状态:加载最新的数据
236  */
237 -(void)refreshStateChange:(UIRefreshControl *)control
238 {
239     TuanGouModel* model =[[TuanGouModel alloc]init];
240     model = _tuanGouArrM[arc4random()];
241     [_tuanGouArrM insertObject:model atIndex:0];
242     [self.myTable reloadData];
243 
244      NSLog(@"第一行");
245      [control endRefreshing];
246     
247 }
248 
249 //指示是否允许高亮显示选中的行
250 - (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath{
251     
252     return YES;
253 }
254 
255 //选中某行时执行
256 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
257     NSLog(@"selected: %ld, row:%ld", indexPath.section, indexPath.row);
258 }
259 //取消选中时执行,这个方法常在表格允许多选时调用执行
260 - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
261     NSLog(@"Deselected: %ld, row:%ld", indexPath.section, indexPath.row);
262 }

小结:框架小,灵活方便,在上拉恐怕下拉的时候能够自定义加载文字以及加载的图样。

}

上拉完毕大旨等同,可在数据加载成功之后调用结束刷新的函数

returncell;

github 链接

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

[self.tableView endFooterRefreshing];[self.tableView endHeaderRefreshing];//数据加载上拉再无数据时,调用函数,可设置加载完成后的样式[self noMoreDada];

84

切实落真实情况势1.导入#import "UITableView Refresh.h" #import "RefreshHeader.h",前边是分类,达成首要职能,前边是上拉抑或下拉亟需导入的头文件。2.设置须求增多的加载类型以及安装本人索要的回掉函数。

[self.tableViewreloadData];

后续会更新优化,暂未有大面积实验,要是开采标题随即联系,谢谢!

[self.tableViewaddFooterWithTarget:selfaction:@selector(footerRereshing)];

tableview的轻型刷新框架,功用简洁实用,拓展性强,可以友善加上必要的来得图片以及提醒文字等。

PS:

[self.tableViewheaderEndRefreshing];

}

56

24

6

18

98

-(void)headerRereshing

2假使在xcode6.0中有荒唐:

}

//2.扫尾刷新

43

19

1,下载地址:http://pan.baidu.com/s/1ntHWClj

@interfaceMyViewController:UIViewController

81

self.tableView.footerPullToRefreshText=@"上拉能够加载更相当多据了";

86

57

}

93

CGRect_rect;//保存当前物理荧屏大小

29

[self.tableViewfooterEndRefreshing];

62

_tableView.delegate=self;

90

cell.textLabel.text=_tableViewData[indexPath.row]1010cc时时彩标准版,;

//2,甘休刷新

4

33

self=[superinitWithNibName:nibNameOrNilbundle:nibBundleOrNil];

#import "MJRefresh.h"

39

-(UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath

3,#import“MJRefresh.h”   这一个能够向来加载.m中

21

-(void)footerRereshing

本文由1010cc时时彩标准版发布于操作系统,转载请注明出处:1010cc时时彩标准版下拉刷新,uitableview下拉刷新

关键词:

上一篇:loadView的使用总结,loadView使用总结

下一篇:没有了