日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內(nèi)最全IT社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當前位置:首頁 > php開源 > 綜合技術(shù) > IOS學習之UiTableView下拉刷新與自動加載更多,百年不變的效果(五)

IOS學習之UiTableView下拉刷新與自動加載更多,百年不變的效果(五)

來源:程序員人生   發(fā)布時間:2015-07-30 14:35:25 閱讀次數(shù):4916次

51勞動節(jié)馬上來臨,小火伴有妹有很激動喲,首先祝天下所有的程序猿節(jié)日快樂!這個51對我來講有點不1樣,我的人生從這個51就轉(zhuǎn)彎了,愛情長跑8年的我結(jié)婚了,1會支付寶賬號我會公布出去,請自覺打款!謝謝合作。

燈光閃起來:

舞蹈跳起來:

歌曲唱起來:

----------------------------------------------------------------------------------------------------------------------------------------------------------

智能世界的里面,做多的是甚么?對,是APP,遮天蔽日的APP隨之襲來,APP死亡潮也隨之出現(xiàn),我們生活在互聯(lián)網(wǎng)的時期里,每一個人都是產(chǎn)品經(jīng)理,聽說,我們每天用的APP不超過8個,反正我每天必用百度云,你曉得,雖然APP多,但是他們都有1個共同點,你們知道是甚么?你們千萬不要告知我是用手機玩的,他們就是都下拉刷新和加載更多,這些產(chǎn)品經(jīng)理所有的共同點,雖然下拉刷新的動畫都不1樣,但是他們的目的只有個,就是獲得服務器最最新的數(shù)據(jù),我們都知道Android里面有很多開源的下拉刷新的第3方比如著名的:Android-PullToRefresh這個開源的很強大啊,支持很多控件,ListView、ViewPager、WevView、ExpandableListView、GridView、(Horizontal )ScrollView、Fragment 點擊下載,固然你也能夠自己寫!既然是土豪的玩的IOS,怎樣可能少了第3方的下拉刷新:但是比較著名的就是:EGOTableViewPullRefreshMJRefresh點擊下載1------------點擊下載2我自認為上拉加載更多對用戶簡直是1直折磨,翻到最后1頁,居然還要上拉1下才能加載更多。1點也不暢,但是我感覺自動加載更多比較人性化,感覺很順!自己的觀點而已!下面我是使MJRefresh這個來學習的,自己集成的自動加載更多,下面來效果圖:


我們發(fā)現(xiàn)我們不需要上拉就能夠自動加載更多,我感覺這類用戶體驗比較好:

繼承步驟:

1:首先我們需要把MJRefresh這個開源的項目下載,把里面

全部考進自己的項目中,要先把這個文件拷貝到自己的項目的目錄中,在xcode上右鍵add file這個文件我們才能把這個所需要的文件考進來,

2:實現(xiàn):直接看代碼:

// // ViewController.m // MyUitableViewRefreshAndMore // // Created by xiaoyuan on 15/4/28. // Copyright (c) 2015年 xiaoyuan. All rights reserved. // #import "MyUitableViewRefreshViewController.h" #import "MJRefresh.h" #import "DataSingleton.h" static const CGFloat MJDuration = 1.0; //#define MJRandomData [NSString stringWithFormat:@"隨機數(shù)據(jù)---%d", arc4random_uniform(1000000)] #define DISPATCH_TIME_NOW (0ull) #define NSEC_PER_SEC 1000000000ull @interface MyUitableViewRefreshViewController ()<UITableViewDelegate,UITableViewDataSource> { UITableView *table; NSMutableArray *data; //判斷是不是加載完成 BOOL isLoadIOver; } @end @implementation MyUitableViewRefreshViewController - (void)viewDidLoad { [super viewDidLoad]; self .view .backgroundColor = [UIColor whiteColor]; self.navigationController.navigationBar.barTintColor = [UIColor redColor]; UILabel*title = [[UILabel alloc] initWithFrame:CGRectZero]; title.text = @"刷新吧小宇宙"; title.backgroundColor =[UIColor clearColor]; title.textColor = [UIColor whiteColor]; self.navigationItem.titleView = title; [title sizeToFit]; [self.navigationController.navigationBar setTranslucent:NO]; __weak typeof(self) weakSelf = self; if(data == nil){ data = [[NSMutableArray alloc] init]; } self.view.backgroundColor = [UIColor whiteColor]; table = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds]; table.backgroundColor =[UIColor whiteColor]; table.separatorStyle = UITableViewCellEditingStyleNone; table.delegate =self; table.dataSource =self; [self.view addSubview:table]; [table addLegendHeaderWithRefreshingBlock:^{ [weakSelf loadNewData :YES]; }]; // 進入自動刷新 [table.legendHeader beginRefreshing]; } - (void)loadNewData:(BOOL)reresh { isLoadIOver = NO; //刷新移除所有數(shù)據(jù) if(reresh){ [data removeAllObjects]; } // 1.添加假數(shù)據(jù) for (int i = 0; i<20; i++) { [data addObject:@(i)]; } // 2.摹擬2秒后刷新表格UI(真實開發(fā)中,可以移除這段gcd代碼) dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(MJDuration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // 刷新表格 [table reloadData]; isLoadIOver = YES; // 拿到當前的下拉刷新控件,結(jié)束刷新狀態(tài) [table.header endRefreshing]; }); } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ //只要大于的數(shù)是小于第1次返回的個數(shù)就行 return data.count > 10? data.count + 1 : data.count; } // -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } -(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 44; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ if([data count]>0){ if(indexPath.row<[data count]){ static NSString *CellIdentifier =@"Cell"; UITableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if(cell == nil){ cell = [[ UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; //避免點擊把分割線弄掉 cell.selectionStyle = UITableViewCellSelectionStyleNone; //這個千萬要記住寫小于44,由于系統(tǒng)默許的就是44 ,這個把我坑壞了,1直找不到緣由,1直以為重用的緣由 //大于44就超越高度,系統(tǒng)就給回收掉了 UIView*view= [[UIView alloc] initWithFrame:CGRectMake(0, 43, 400, 1)]; view.backgroundColor = [UIColor grayColor]; [cell addSubview:view]; } cell.textLabel.text = [NSString stringWithFormat:@"%@",[data objectAtIndex:indexPath.row]]; cell .textLabel.textAlignment = NSTextAlignmentCenter; return cell; } } //加載更多 if(isLoadIOver){ [self loadNewData:NO]; } return [DataSingleton.Instance getLoadMoreCell:table andIsLoadOver:NO andLoadOverString:@"正在加載..." andLoadingString:(YES ? @"正在加載" : @"下面10個") andIsLoading:YES]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end

DataSingleton類:

// // DataSingleton.h // MyUiTableRefresh // // Created by xiaoyuan on 15/4/29. // Copyright (c) 2015年 xiaoyuan. All rights reserved. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import "LoadingCell.h" @interface DataSingleton : NSObject #pragma 單例模式 + (DataSingleton *) Instance; + (id)allocWithZone:(NSZone *)zone; //返回標示正在加載的選項 - (UITableViewCell *)getLoadMoreCell:(UITableView *)tableView andIsLoadOver:(BOOL)isLoadOver andLoadOverString:(NSString *)loadOverString andLoadingString:(NSString *)loadingString andIsLoading:(BOOL)isLoading; @end
// // DataSingleton.m // MyUiTableRefresh // // Created by xiaoyuan on 15/4/29. // Copyright (c) 2015年 xiaoyuan. All rights reserved. // #import "DataSingleton.h" #import <QuartzCore/QuartzCore.h> @implementation DataSingleton - (UITableViewCell *)getLoadMoreCell:(UITableView *)tableView andIsLoadOver:(BOOL)isLoadOver andLoadOverString:(NSString *)loadOverString andLoadingString:(NSString *)loadingString andIsLoading:(BOOL)isLoading { LoadingCell * cell = [tableView dequeueReusableCellWithIdentifier:@"loadingCell"]; if (!cell) { NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"LoadingCell" owner:self options:nil]; for (NSObject *o in objects) { if ([o isKindOfClass:[LoadingCell class]]) { cell = (LoadingCell *)o; break; } } } cell.lbl.font = [UIFont boldSystemFontOfSize:15 - 2]; cell.lbl.text = isLoadOver ? loadOverString : loadingString; if (isLoading) { cell.loading.hidden = NO; [cell.loading startAnimating]; } else { cell.loading.hidden = YES; [cell.loading stopAnimating]; } return cell; } #pragma 單例模式定義 static DataSingleton * instance = nil; +(DataSingleton *) Instance { if(nil == instance) { @synchronized(self) { if(nil == instance) { instance = [[DataSingleton alloc] init]; } } } return instance; } //-(void) dealloc //{ // [instance release]; // [super dealloc]; //} +(id)allocWithZone:(NSZone *)zone { @synchronized(self) { if(instance == nil) { instance = [super allocWithZone:zone]; return instance; } } return nil; } @end

主要代碼就是這些,還有1個LoadingCell類,就不貼了,這主要是MJReresh得基礎上加上自動加載,固然里面還有1些邏輯需要待開發(fā)的,比如網(wǎng)絡的緣由了,還有數(shù)據(jù)全部加載完成了,這些就看需求來改!最后感謝李明杰老師,開源了這么優(yōu)秀的代碼。祝大家51快樂,東北走起,求偶遇!

代碼下載







生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 日韩欧美一 | 日韩高清免费在线 | 国产成人综合亚洲 | 国产麻豆久久 | 九九综合九九 | 性色一区二区三区 | 精品午夜视频 | 欧美日韩国产亚洲乱码字幕 | 国产一区二区在线观看视频 | 国产成人精品免高潮在线观看 | 国产精品久久久久久亚洲调教 | 精品久久影院 | 成人在线网站 | 国产精品视频一区二区三区不卡 | 免费成人一级片 | www.av在线 | 亚洲欧美激情精品一区二区 | 国产精品久久久久久久va果冻 | 精品成人一区二区三区 | 国产不卡a | 久久久久久网 | а天堂中文在线官网 | 在线日韩电影 | 国产黄网| 日韩看片 | 一区二区三区国产 | 欧日韩一区二区三区 | 欧美在线a | 视频一区二区在线 | 国产精品一区二区三区四区五区 | 三区在线 | 日韩一区二区不卡 | 国产精品视频免费观看 | 国产精品成人aaaaa网站 | 亚洲一区 欧美一区 | 久久久久国产一区二区三区 | 66精品 | 成人免费视频观看视频 | 久久久久久久久久久久久女国产乱 | 精品在线一区二区三区 | 久久久精品999 |