成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

iPhone中使用UITableView實(shí)現(xiàn)分頁效果(附代碼)

移動開發(fā) iOS
本文介紹的是iPhone中使用UITableView實(shí)現(xiàn)分頁效果。詳細(xì)講解了UITableView的使用方法,先來看內(nèi)容詳解。

iPhone中使用UITableView實(shí)現(xiàn)分頁效果是本文要介紹的內(nèi)容,UITableview 能夠列表顯示許多內(nèi)容,也是我們開發(fā)中經(jīng)常用的一個組件。我們經(jīng)常會分頁顯示列表,如先顯示 10 條記錄,點(diǎn)擊更多在添加 10 條,以此類推,下面是實(shí)現(xiàn)類似更多顯示的一個 demo。

實(shí)現(xiàn)的效果如下:

iPhone中使用UITableView實(shí)現(xiàn)分頁效果

點(diǎn)擊 “More…”,實(shí)現(xiàn)后面的效果.

實(shí)現(xiàn)的思路:

基本上就是數(shù)據(jù)源里先只放10條, 點(diǎn)擊***一個cell時, 添加更多的數(shù)據(jù)到數(shù)據(jù)源中。

處理"加載更多"的那個cell的選擇事件,觸發(fā)一個方法來加載更多數(shù)據(jù)到列表。

indexPathForRow插入數(shù)據(jù)。

實(shí)現(xiàn)過程如下:

  1. #import <UIKit/UIKit.h> 
  2.  
  3. @interface iphone_tableMoreViewController : UIViewController   
  4. <UITableViewDelegate,UITableViewDataSource>{   
  5.       
  6.     IBOutlet UITableView *myTableView;   
  7.     NSMutableArray *items;   
  8. }   
  9. @property (nonatomic,retain) UITableView *myTableView;   
  10. @property (nonatomic,retain) NSMutableArray *items;   
  11. @end  
  12.  
  13. #import "iphone_tableMoreViewController.h"   
  14. @implementation iphone_tableMoreViewController   
  15. @synthesize items,myTableView;   
  16. - (void)viewDidLoad {   
  17.     [super viewDidLoad];   
  18.     items=[[NSMutableArray alloc] initWithCapacity:0];   
  19.     for (int i=0; i<10; i++) {   
  20.         [items addObject:[NSString stringWithFormat:@"cell %i",i]];   
  21.     }   
  22. }   
  23. - (void)didReceiveMemoryWarning {   
  24.     [super didReceiveMemoryWarning];   
  25. }  
  26.  
  27. - (void)viewDidUnload {   
  28.     items=nil;   
  29.     self.myTableView=nil;   
  30. }   
  31. - (void)dealloc {   
  32.     [self.myTableView release];   
  33.     [items release];   
  34.     [super dealloc];   
  35. }  
  36.  
  37. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {   
  38.     int count = [items count];   
  39.     return  count + 1;   
  40. }   
  41. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {   
  42.     static NSString *tag=@"tag";   
  43.     UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:tag];   
  44.     if (cell==nil) {   
  45.         cell=[[[UITableViewCell alloc] initWithFrame:CGRectZero   
  46.                                      reuseIdentifier:tag] autorelease];   
  47.     }      
  48.     if([indexPath row] == ([items count])) {   
  49.         //創(chuàng)建loadMoreCell   
  50.         cell.textLabel.text=@"More..";   
  51.     }else {   
  52.     cell.textLabel.text=[items objectAtIndex:[indexPath row]];      
  53.     }   
  54.     return cell;   
  55. }   
  56. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {   
  57.       
  58.  
  59.     if (indexPath.row == [items count]) {   
  60.         UITableViewCell *loadMoreCell=[tableView cellForRowAtIndexPath:indexPath];   
  61.         loadMoreCell.textLabel.text=@"loading more …";   
  62.         [self performSelectorInBackground:@selector(loadMore) withObject:nil];   
  63.        [tableView deselectRowAtIndexPath:indexPath animated:YES];   
  64.         return;   
  65.     }   
  66.     //其他cell的事件   
  67.       
  68. }   
  69. -(void)loadMore   
  70. {   
  71.     NSMutableArray *more;   
  72.     more=[[NSMutableArray alloc] initWithCapacity:0];   
  73.     for (int i=0; i<10; i++) {   
  74.         [more addObject:[NSString stringWithFormat:@"cell ++%i",i]];   
  75.     }   
  76.     //加載你的數(shù)據(jù)   
  77.     [self performSelectorOnMainThread:@selector(appendTableWith:) withObject:more waitUntilDone:NO];   
  78.     [more release];   
  79. }   
  80. -(void) appendTableWith:(NSMutableArray *)data   
  81. {   
  82.     for (int i=0;i<[data count];i++) {   
  83.         [items addObject:[data objectAtIndex:i]];   
  84.     }   
  85.     NSMutableArray *insertIndexPaths = [NSMutableArray arrayWithCapacity:10];   
  86.     for (int ind = 0; ind < [data count]; ind++) {   
  87.         NSIndexPath    *newPath =  [NSIndexPath indexPathForRow:[items indexOfObject:[data objectAtIndex:ind]] inSection:0];   
  88.         [insertIndexPaths addObject:newPath];   
  89.     }   
  90.    [self.myTableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationFade];   
  91.       
  92. }   
  93. @end 

源代碼:http://easymorse-iphone.googlecode.com/svn/trunk/iphone.tableMore/

小結(jié):iPhone中使用UITableView實(shí)現(xiàn)分頁效果(附代碼)的內(nèi)容介紹完了,希望通過本文的學(xué)習(xí)對你有所幫助!

責(zé)任編輯:zhaolei 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2011-07-27 11:19:33

iPhone UITableVie

2011-08-10 14:40:23

iPhone動畫

2010-09-17 10:26:01

iPhone

2011-07-08 10:15:15

IPhone 動畫

2011-08-18 13:58:34

iPhone開發(fā)NSOperation異步

2011-07-20 14:53:28

iPhone NSLocalize 國際化

2011-08-11 13:26:30

iPhoneNSLocalized

2011-08-19 10:01:09

iPhone應(yīng)用SqliteUITableView

2011-08-02 17:14:41

iPhone應(yīng)用 UITableVie

2011-07-08 15:08:16

iPhone 圖片

2011-07-27 11:14:37

iPhone UITableVie

2011-08-17 14:57:31

iPhone應(yīng)用視頻播放

2011-08-22 14:21:24

iPhone開發(fā)UIView Anim

2011-08-12 14:04:53

iPhone動畫

2011-08-15 13:44:07

iPhone開發(fā)UITableView

2011-08-15 15:26:20

iPhone開發(fā)CocoaXML

2011-07-20 15:20:14

IPhone AVAudioRec

2011-07-29 13:55:10

IPhone 動畫

2013-07-29 14:28:43

JQueryJQuery實(shí)現(xiàn)分頁分頁程序代碼

2011-08-16 18:13:42

IPhone開發(fā)UIView動畫
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 亚洲国产高清免费 | 成人国产一区二区三区精品麻豆 | 激情欧美日韩一区二区 | 国产欧美视频一区二区三区 | 国产高清一区二区三区 | 91福利电影在线观看 | 手机av在线 | 亚洲精品一区二区冲田杏梨 | 欧美国产日韩精品 | 天天草视频| h视频免费在线观看 | 国产免费让你躁在线视频 | 成人在线观看欧美 | 亚洲欧美一区在线 | 久久九精品| 91精品国产91久久久久游泳池 | 成人在线免费 | 国产精品久久精品 | 日韩美女一区二区三区在线观看 | www.xxxx欧美 | 欧美中文字幕在线观看 | 欧美婷婷 | 日本免费在线观看视频 | 九九久久这里只有精品 | 国产精品成人在线播放 | 国产精品视频二区三区 | 中文字幕国产第一页 | 国产精品视频999 | 亚洲激情在线观看 | 91亚洲国产成人久久精品网站 | 精品美女 | 在线欧美一区 | 日本成人在线观看网站 | 翔田千里一区二区 | 国产一区在线视频 | av在线播放免费 | 日韩在线播放视频 | 福利视频一二区 | 日韩一区二区三区视频在线观看 | 欧美一区二区三区 | 国精产品一区一区三区免费完 |