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

iPhone中使用UITableView實現分頁效果(附代碼)

移動開發 iOS
本文介紹的是iPhone中使用UITableView實現分頁效果。詳細講解了UITableView的使用方法,先來看內容詳解。

iPhone中使用UITableView實現分頁效果是本文要介紹的內容,UITableview 能夠列表顯示許多內容,也是我們開發中經常用的一個組件。我們經常會分頁顯示列表,如先顯示 10 條記錄,點擊更多在添加 10 條,以此類推,下面是實現類似更多顯示的一個 demo。

實現的效果如下:

iPhone中使用UITableView實現分頁效果

點擊 “More…”,實現后面的效果.

實現的思路:

基本上就是數據源里先只放10條, 點擊***一個cell時, 添加更多的數據到數據源中。

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

indexPathForRow插入數據。

實現過程如下:

  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.         //創建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.     //加載你的數據   
  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/

小結:iPhone中使用UITableView實現分頁效果(附代碼)的內容介紹完了,希望通過本文的學習對你有所幫助!

責任編輯:zhaolei 來源: 互聯網
相關推薦

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開發NSOperation異步

2011-08-11 13:26:30

iPhoneNSLocalized

2011-07-20 14:53:28

iPhone NSLocalize 國際化

2011-08-19 10:01:09

iPhone應用SqliteUITableView

2011-08-02 17:14:41

iPhone應用 UITableVie

2011-07-08 15:08:16

iPhone 圖片

2011-08-17 14:57:31

iPhone應用視頻播放

2011-07-27 11:14:37

iPhone UITableVie

2011-08-22 14:21:24

iPhone開發UIView Anim

2011-08-12 14:04:53

iPhone動畫

2011-08-15 15:26:20

iPhone開發CocoaXML

2011-08-15 13:44:07

iPhone開發UITableView

2011-07-20 15:20:14

IPhone AVAudioRec

2011-08-16 18:13:42

IPhone開發UIView動畫

2013-07-29 14:28:43

JQueryJQuery實現分頁分頁程序代碼

2011-07-29 13:55:10

IPhone 動畫
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 最新日韩在线 | 亚洲午夜网 | 影音先锋久久 | 日日操夜夜操天天操 | 精品国产一区二区在线 | 先锋资源亚洲 | 中文字幕一二三 | 一级女毛片 | 自拍视频网站 | 日本在线视频一区二区 | 亚洲精品一级 | 中文字幕在线精品 | 美女国产精品 | 久久中文字幕一区 | 四色成人av永久网址 | 91 中文字幕 | 亚洲 中文 欧美 日韩 在线观看 | 精品亚洲一区二区 | 亚洲成人动漫在线观看 | 在线播放第一页 | 国产欧美日韩一区 | 99精品国产一区二区三区 | 久久综合久 | 99精品网| 1级黄色大片 | 亚洲一区有码 | 国产91在线 | 亚洲 | 国产精品 欧美精品 | 四虎影院在线免费观看 | 中国大陆高清aⅴ毛片 | av天天看| www.亚洲国产精品 | 亚洲欧美在线视频 | 国产一区二区三区在线 | 四虎影视免费观看 | 日韩免费高清视频 | 99精品一区二区三区 | 国产一区二区三区亚洲 | 91精品综合久久久久久五月天 | 久久精品性视频 | 天天久久 |