国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

香港云服务器
服務器之家 - 編程語言 - IOS - iOS開發之UITableView與UISearchController實現搜索及上拉加載,下拉刷新實例代碼

iOS開發之UITableView與UISearchController實現搜索及上拉加載,下拉刷新實例代碼

2021-01-16 14:58甘林夢 IOS

這篇文章主要介紹了iOS開發之UITableView與UISearchController實現搜索及上拉加載,下拉刷新實例代碼的相關資料,需要的朋友可以參考下

廢話不多說了,直接給大家貼代碼了。

具體代碼如下所示:

?
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
180
181
182
183
184
185
186
187
188
189
190
#import "ViewController.h"
#import "TuanGouModel.h"
#import "TuanGouTableViewCell.h"
#define kDeviceWidth [UIScreen mainScreen].bounds.size.width
#define kDeviceHeight [UIScreen mainScreen].bounds.size.height
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource,UISearchResultsUpdating>
{
UISearchController * _sscller;
}
@property(nonatomic,strong)NSMutableArray* secArrM;
@property(nonatomic,strong) NSMutableArray* tuanGouArrM;
@property(nonatomic,strong)UITableView* myTable;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self createNa];
self.myTable.backgroundColor = [UIColor lightGrayColor];
[self createsecB];
[self setupRefresh];
self.title = @"美食家";
}
#pragma mark - 導航
-(void)createNa{
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithTitle:@"Edit" style:UIBarButtonItemStylePlain target:self action:@selector(tableEdit:)];
self.navigationItem.rightBarButtonItem = rightItem;
self.title = @"美食家";
}
// 點擊導航右側編輯按鈕時,讓表格可編輯
-(void)tableEdit:(UIBarButtonItem *) btnItem{
// if (self.myTable.editing == NO ) { // 沒有處于編輯狀態,導航按鈕文字為“Edit”
// // 點擊“編輯”文字,讓表格處于編輯狀態,并把按鈕的文字修改為“Done"
// self.myTable.editing = YES;
//
// }else{
// // 編輯狀態下,點擊”Done"按鈕,取消表格的編輯狀態,修改導航按鈕文字為"Edit"
// self.myTable.editing = NO;
// btnItem.title = @"Edit" ;
// self.navigationItem.rightBarButtonItems = @[btnItem];
// }
}
-(void)createsecB{
_sscller = [[UISearchController alloc]initWithSearchResultsController:nil];
_sscller.searchResultsUpdater = self;
self.myTable.tableHeaderView = _sscller.searchBar;
}
-(NSMutableArray *)secArrM{
if (_secArrM == nil) {
return _secArrM = [NSMutableArray array];
}else{
return _secArrM;
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#pragma mark - 表格懶加載
-(UITableView *)myTable{
if (_myTable == nil) {
_myTable = [[UITableView alloc]initWithFrame:CGRectMake(, , kDeviceWidth, kDeviceHeight) style:UITableViewStylePlain];
[self.view addSubview:_myTable];
_myTable.delegate = self;
_myTable.dataSource = self;
_myTable .separatorStyle = UITableViewCellSeparatorStyleSingleLineEtched;
}
return _myTable;
}
#pragma mark - 團購數據懶加載
-(NSMutableArray *)tuanGouArrM{
if (_tuanGouArrM == nil) {
_tuanGouArrM = [NSMutableArray array];
NSString* plistPath = [[NSBundle mainBundle]pathForResource:@"tgs.plist" ofType:nil];
NSArray* tuanArr = [NSArray arrayWithContentsOfFile:plistPath];
for (NSDictionary* dict in tuanArr) {
TuanGouModel* model =[[TuanGouModel alloc]initWithDict:dict];
[_tuanGouArrM addObject:model];
}
}
return _tuanGouArrM;
}
#pragma mark - 數據源協議
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if ( _sscller.active ) { //搜索結果表格
return self.secArrM.count;
}
else{
return self.tuanGouArrM.count;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//注冊
[tableView registerClass:[TuanGouTableViewCell class] forCellReuseIdentifier:@"tuanCell"];
//重置
TuanGouTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"tuanCell"forIndexPath:indexPath];
cell.backgroundColor = [UIColor yellowColor];
// 選中風格
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if( !_sscller.active ){
cell.tuanGouModel = self.tuanGouArrM[indexPath.row];
}else{ //搜索結果
cell.tuanGouModel = self.secArrM[indexPath.row];
}
return cell;
}
#pragma mark - TableV協議
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return ;
}
-(void)updateSearchResultsForSearchController:(UISearchController *)searchController{
[self.secArrM removeAllObjects];
for (int j = ; j < _tuanGouArrM.count; j++) {
TuanGouModel* model =[[TuanGouModel alloc]init];
model = _tuanGouArrM[j];
if ([model.title isEqualToString: _sscller.searchBar.text]) {
[self.secArrM addObject: model];
}
}
[self.myTable reloadData];
}
//允許Menu菜單
-(BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
//每個cell都可以點擊出現Menu菜單
-(BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
return YES;
}
-(void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender{
NSLog(@"長按");
if (action ==@selector(copy:)) {
NSLog(@"copy");
}
if (action ==@selector(cut:)) {
NSLog(@"cut");
}
if (action ==@selector(paste:)) {
NSLog(@"paste");
}
if (action ==@selector(selectAll:)) {
NSLog(@"selectAll");
}
}
//上拉加載
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row == self.tuanGouArrM.count - ) {
NSLog(@"最后一行");
TuanGouModel* model =[[TuanGouModel alloc]init];
model = _tuanGouArrM[arcrandom()%];
[_tuanGouArrM addObject:model];
[self.myTable reloadData];
}
}
//下拉刷新
-(void)setupRefresh
{
//.添加刷新控件
UIRefreshControl *control=[[UIRefreshControl alloc]init];
[control addTarget:self action:@selector(refreshStateChange:) forControlEvents:UIControlEventValueChanged];
[self.myTable addSubview:control];
//.馬上進入刷新狀態,并不會觸發UIControlEventValueChanged事件
[control beginRefreshing];
// .加載數據
[self refreshStateChange:control];
}
/**
* UIRefreshControl進入刷新狀態:加載最新的數據
*/
-(void)refreshStateChange:(UIRefreshControl *)control
{
TuanGouModel* model =[[TuanGouModel alloc]init];
model = _tuanGouArrM[arcrandom()%];
[_tuanGouArrM insertObject:model atIndex:];
[self.myTable reloadData];
NSLog(@"第一行");
[control endRefreshing];
}
//指示是否允許高亮顯示選中的行
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
//選中某行時執行
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"selected: %ld, row:%ld", indexPath.section, indexPath.row);
}
//取消選中時執行,這個方法常在表格允許多選時調用執行
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"Deselected: %ld, row:%ld", indexPath.section, indexPath.row);
}

以上代碼是hi小編給大家介紹的iOS開發之UITableView與UISearchController實現搜索及上拉加載,下拉刷新實例代碼,希望對大家有所幫助!

延伸 · 閱讀

精彩推薦
  • IOSiOS中MD5加密算法的介紹和使用

    iOS中MD5加密算法的介紹和使用

    MD5加密是最常用的加密方法之一,是從一段字符串中通過相應特征生成一段32位的數字字母混合碼。對輸入信息生成唯一的128位散列值(32個字符)。這篇文...

    LYSNote5432021-02-04
  • IOSiOS自定義UICollectionViewFlowLayout實現圖片瀏覽效果

    iOS自定義UICollectionViewFlowLayout實現圖片瀏覽效果

    這篇文章主要介紹了iOS自定義UICollectionViewFlowLayout實現圖片瀏覽效果的相關資料,需要的朋友可以參考下...

    jiangamh8882021-01-11
  • IOSiOS實現控制屏幕常亮不變暗的方法示例

    iOS實現控制屏幕常亮不變暗的方法示例

    最近在工作中遇到了要將iOS屏幕保持常亮的需求,所以下面這篇文章主要給大家介紹了關于利用iOS如何實現控制屏幕常亮不變暗的方法,文中給出了詳細的...

    隨風13332021-04-02
  • IOS詳解iOS中多個網絡請求的同步問題總結

    詳解iOS中多個網絡請求的同步問題總結

    這篇文章主要介紹了詳解iOS中多個網絡請求的同步問題總結,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧...

    liang199111302021-03-15
  • IOSiOS中滑動控制屏幕亮度和系統音量(附加AVAudioPlayer基本用法和Masonry簡單使用)

    iOS中滑動控制屏幕亮度和系統音量(附加AVAudioPlayer基本用法和

    這篇文章主要介紹了iOS中滑動控制屏幕亮度和系統音量(附加AVAudioPlayer基本用法和Masonry簡單使用)的相關資料,需要的朋友可以參考下...

    CodingFire13652021-02-26
  • IOSiOS中UILabel實現長按復制功能實例代碼

    iOS中UILabel實現長按復制功能實例代碼

    在iOS開發過程中,有時候會用到UILabel展示的內容,那么就設計到點擊UILabel復制它上面展示的內容的功能,也就是Label長按復制功能,下面這篇文章主要給大...

    devilx12792021-04-02
  • IOSiOS開發技巧之狀態欄字體顏色的設置方法

    iOS開發技巧之狀態欄字體顏色的設置方法

    有時候我們需要根據不同的背景修改狀態欄字體的顏色,下面這篇文章主要給大家介紹了關于iOS開發技巧之狀態欄字體顏色的設置方法,文中通過示例代碼...

    夢想家-mxj8922021-05-10
  • IOSiOS開發之視圖切換

    iOS開發之視圖切換

    在iOS開發中視圖的切換是很頻繁的,獨立的視圖應用在實際開發過程中并不常見,除非你的應用足夠簡單。在iOS開發中常用的視圖切換有三種,今天我們將...

    執著丶執念5272021-01-16
1090
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 日韩一级大片 | 在线免费观看黄色 | 黄片毛片在线观看 | 久久99精品国产.久久久久 | 久久草在线视频 | 久久水蜜桃 | 成人免费在线播放 | 伊人99| 精品视频在线一区 | 精品久久一区二区三区 | 午夜视频在线观看一区二区三区 | 91.成人天堂一区 | 成人免费在线电影 | 久久久久一区 | 成人欧美一区二区三区在线观看 | 精品免费国产 | 精品美女在线观看视频在线观看 | 青青草原综合久久大伊人精品 | 午夜成人在线视频 | 欧美一区二区三区在线视频 | 日韩在线精品强乱中文字幕 | 91色在线视频 | 欧美a级网站 | 亚洲精品一区久久久久久 | 精品亚洲第一 | 欧美亚洲高清 | 欧美一区二区在线视频 | 日韩成人在线网 | 激情综合色综合久久综合 | 亚洲国产精品久久久 | 一区视频| ririsao久久精品一区 | 成人av电影网 | 国产精品一区在线 | 成人影院av | 在线观看成人 | 欧美综合影院 | 一区二区三区免费在线 | 国产精选一区二区三区不卡催乳 | xx视频在线观看 | 欧美a在线看|