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

詳解iPhone開發應用之表視圖分組實現代碼

移動開發 iOS
本文介紹的是iPhone開發應用中表視圖分組的實現,主要是以代碼實現視圖的分組內容,先來看本文詳細講解。

iPhone開發應用中表視圖分組的實現是本文要介紹的內容,主要是以代碼實現視圖的分組,不多說,先來看本文詳細內容,貼一張圖:

iPhone開發應用之表視圖分組實現代碼

1.先創建 plist文件,

2.主界面 放置一個 table view控件

3.接口代碼

  1. @interface SectionsViewController : UIViewController <UITableViewDataSource,UITableViewDelegate> {  
  2. NSDictionary *names;  
  3. NSArray *keys;  
  4. }  
  5. @property (nonatomic, retain) NSDictionary *names;  
  6. @property (nonatomic, retain) NSArray *keys;  
  7.  
  8. 4.實現代碼  
  9.  
  10. @implementation SectionsViewController  
  11. @synthesize names;  
  12. @synthesize keys;  
  13.  
  14. - (void)viewDidLoad {  
  15. NSString *path=[[NSBundle mainBundle] pathForResource:@"sortednames"   
  16.   ofType:@"plist"]; //獲取屬性列表的路徑,賦給path   
  17. NSDictionary *dict=[[NSDictionary alloc]   
  18. initWithContentsOfFile:path];  //將 路徑path下的數據表 初始化字典dict  
  19. self.names = dict; //字典dict 賦給names  
  20.  
  21. //因為 names 有 retain 屬性。 當給names賦值時 ,dict會自動retain(增一),此時dict的retain count=2;  
  22. [dict release];  
  23. //for (int i=0; i<[[names allKeys] count]; i++) {  
  24.  
  25. // NSLog(@"%@\n",[[names allKeys] objectAtIndex:i]);  
  26. // }  
  27. //  
  28. NSArray *array=[[names allKeys] sortedArrayUsingSelector:  
  29. @selector(compare:)]; //給所有 keys 值按字母順序排序  
  30. //for (int i=0; i<[array count]; i++) {  
  31. // NSLog(@"%@\n",[array objectAtIndex:i]);  
  32. // }  
  33.  
  34. self.keys = array; //將 array對象賦給 keys  
  35.  
  36.    
  37. }  
  38.  
  39. - (void)didReceiveMemoryWarning {  
  40. // Releases the view if it doesn't have a superview.  
  41.     [super didReceiveMemoryWarning];  
  42. // Release any cached data, images, etc that aren't in use.  
  43. }  
  44. - (void)viewDidUnload {  
  45. // Release any retained subviews of the main view.  
  46. // e.g. self.myOutlet = nil;  
  47. self.names = nil;  
  48. self.keys = nil;  
  49. }  
  50.  
  51. - (void)dealloc {  
  52. [names release];  
  53. [keys release];  
  54.     [super dealloc];  
  55. }  
  56.  
  57. #pragma mark -  
  58. #pragma mark Table View Data Source Methods  
  59. // 返回有多少個分區  
  60. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView  
  61. {  
  62.     return [keys count];  //獲取分區的數量  
  63. }  
  64. //返回 每個分區 有多少行  
  65. - (NSInteger)tableView:(UITableView *)tableView   
  66.  numberOfRowsInSection:(NSInteger)section  
  67. {  
  68.     NSString *key = [keys objectAtIndex:section]; //section為其中一個分區,獲取section的索引  
  69.     NSArray *nameSection = [names objectForKey:key];  //根據索引獲取分區里面的所有數據  
  70.     return [nameSection count];     //返回分區里的行的數量  
  71. }  
  72.  
  73. //返回 當前需要顯示的cell, 可能是 為了節省內存  
  74. - (UITableViewCell *)tableView:(UITableView *)tableView   
  75.          cellForRowAtIndexPath:(NSIndexPath *)indexPath  
  76. {  
  77. //NSLog(@"tianshi\n");  
  78.     NSUInteger section = [indexPath section];//返回第幾分區  
  79.     NSUInteger row = [indexPath row];//獲取第幾分區的第幾行  
  80.     NSString *key = [keys objectAtIndex:section]; //返回 分區的索引key  
  81.     NSArray *nameSection = [names objectForKey:key];//返回 根據key獲得:當前分區的所有內容,  
  82.     static NSString *SectionsTableIdentifier = @"SectionsTableIdentifier";  
  83. //判斷cell是否存在,如果沒有,則新建一個  
  84.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:  
  85.                              SectionsTableIdentifier ];  
  86.     if (cell == nil) {  
  87.         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault   
  88.                                        reuseIdentifier: SectionsTableIdentifier ] autorelease];  
  89.     }  
  90.     //給cell賦值  
  91.     cell.textLabel.text = [nameSection objectAtIndex:row];  
  92.     return cell;  
  93. }  
  94.  
  95. //為每一個分區指定一個名稱,現在的名稱為key的值  
  96. - (NSString *)tableView:(UITableView *)tableView   
  97. titleForHeaderInSection:(NSInteger)section  
  98. {  
  99.     NSString *key = [keys objectAtIndex:section];  
  100.     return key;  
  101. }  
  102. //添加索引的值,為右側的A----E  
  103. - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView  
  104. {  
  105.     return keys;  

小結:詳解iPhone開發應用之表視圖分組實現代碼的內容介紹完了,希望本文對你有所幫助!

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

2011-08-15 18:02:32

iPhone開發表視圖

2011-08-12 10:04:24

iPhone開發視圖

2011-08-11 11:51:07

iPhone鍵盤

2011-08-17 15:10:21

iPhone開發Web視圖

2011-08-11 10:16:23

iPhoneUIView視圖

2011-08-11 10:27:37

iPhoneUIView視圖

2011-08-10 10:23:20

iPhoneArchivingNSCoder

2011-08-16 19:02:23

iPhone開發繪圖

2011-07-25 14:44:41

iPhone iPhone開發 截屏

2011-08-12 11:31:46

iPhoneUIView動畫

2011-08-15 10:15:00

iPhone開發警告框

2011-08-16 14:54:12

iphone開發APP

2011-08-10 17:37:00

iPhoneASIHTTPRequ

2011-08-15 11:23:41

iPhone開發循環滾動UIScrollVie

2011-08-15 11:13:06

IOS開發并發Dispatch Qu

2011-08-19 14:27:29

iPhone開發

2011-07-20 15:20:14

IPhone AVAudioRec

2011-08-15 11:37:20

iPhone開發Mask

2011-07-27 11:14:37

iPhone UITableVie

2011-08-12 14:33:06

iPhone緩存文件
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 成人在线免费视频观看 | 北条麻妃视频在线观看 | 国产日韩久久久久69影院 | 欧美精品一区二区三区四区 在线 | 国产黄色在线观看 | 国产电影一区二区三区爱妃记 | 日韩av看片 | 伦理片97 | 欧美综合一区 | 国产99免费| 日韩精品一区二区三区中文在线 | 欧美一级欧美三级在线观看 | 久久成人精品 | www.干| 91视视频在线观看入口直接观看 | 在线亚洲免费视频 | 91热在线| av一级久久| 91在线精品秘密一区二区 | 精品成人av | 久久精品亚洲精品国产欧美 | 91高清免费观看 | 偷拍自拍在线观看 | 国产一区二区av | 在线观看日本高清二区 | 香蕉视频1024| 羞羞视频在线网站观看 | 日本福利视频免费观看 | 久久精品av麻豆的观看方式 | 精品在线免费观看视频 | 伊人精品视频 | 日日夜夜操天天干 | 91网站视频在线观看 | 久久人体视频 | 欧美看片 | 午夜影院在线播放 | 一本色道精品久久一区二区三区 | 亚洲精品一区二区三区蜜桃久 | 免费在线精品视频 | 亚洲精品福利在线 | 国产免费福利 |