自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iPhone應(yīng)用開發(fā) UITableView學(xué)習(xí)點(diǎn)滴詳解

移動(dòng)開發(fā) iOS
本文介紹的是iPhone應(yīng)用開發(fā) UITableView學(xué)習(xí)點(diǎn)滴詳解,主要以代碼實(shí)現(xiàn),我們來(lái)看詳細(xì)內(nèi)容。

iPhone應(yīng)用開發(fā) UITableView學(xué)習(xí)點(diǎn)滴詳解是本文要介紹的內(nèi)容,內(nèi)容不多,主要是以代碼實(shí)現(xiàn)UITableView的學(xué)習(xí)點(diǎn)滴,我們來(lái)看內(nèi)容。

-、建立 UITableView

  1. DataTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 420)];  
  2. [DataTable setDelegate:self];  
  3. [DataTable setDataSource:self];  
  4. [self.view addSubview:DataTable];  
  5. [DataTable release]; 

二、UITableView各Method說(shuō)明

  1. //Section總數(shù)  
  2. - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{  
  3.  return TitleData;  
  4. }  
  5.  
  6. // Section Titles  
  7. //每個(gè)section顯示的標(biāo)題  
  8. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{  
  9.  return @"";  
  10. }  
  11.  
  12. //指定有多少個(gè)分區(qū)(Section),默認(rèn)為1  
  13. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {  
  14.  return 4;  
  15. }  
  16.  
  17. //指定每個(gè)分區(qū)中有多少行,默認(rèn)為1  
  18. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{  
  19. }  
  20.  
  21. //繪制Cell  
  22. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {  
  23. static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";  
  24.     
  25.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:  
  26.                              SimpleTableIdentifier];  
  27.     if (cell == nil) {    
  28.         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  
  29.                                        reuseIdentifier: SimpleTableIdentifier] autorelease];  
  30.  }  
  31.  cell.imageView.image=image;//未選cell時(shí)的圖片  
  32.  cell.imageView.highlightedImage=highlightImage;//選中cell后的圖片  
  33.  cell.text=//.....  
  34.  return cell;  
  35. }  
  36.  
  37. //行縮進(jìn)  
  38. -(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath{  
  39.  NSUInteger row = [indexPath row];  
  40.  return row;  
  41. }  
  42.  
  43. //改變行的高度  
  44. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{  
  45.     return 40;  
  46. }  
  47.  
  48. //定位  
  49. [TopicsTable setContentOffset:CGPointMake(0, promiseNum * 44 + Chapter * 20)];  
  50.  
  51. //返回當(dāng)前所選cell  
  52. NSIndexPath *ip = [NSIndexPath indexPathForRow:row inSection:section];  
  53. [TopicsTable selectRowAtIndexPath:ip animated:YES scrollPosition:UITableViewScrollPositionNone];  
  54.  
  55. [tableView setSeparatorStyle:UITableViewCellSelectionStyleNone];  
  56.  
  57. //選中Cell響應(yīng)事件  
  58. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{  
  59.  
  60.  [tableView deselectRowAtIndexPath:indexPath animated:YES];//選中后的反顯顏色即刻消失  
  61. }  
  62.  
  63. //判斷選中的行(阻止選中***行)  
  64. -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath  
  65. {  
  66.     NSUInteger row = [indexPath row];  
  67.     if (row == 0)  
  68.         return nil;  
  69.      
  70.     return indexPath;  
  71. }  
  72.  
  73. //劃動(dòng)cell是否出現(xiàn)del按鈕  
  74. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {  
  75. }  
  76.  
  77. //編輯狀態(tài)  
  78. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle  
  79. forRowAtIndexPath:(NSIndexPath *)indexPath  
  80. {  
  81. }  
  82.  
  83. [topicsTable setContentSize:CGSizeMake(0,controller.promiseNum * 44)];  
  84. //右側(cè)添加一個(gè)索引表  
  85. - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{  
  86. }  
  87.  
  88. //返回Section標(biāo)題內(nèi)容  
  89. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{  
  90. }  
  91.  
  92. //自定義劃動(dòng)時(shí)del按鈕內(nèi)容  
  93. - (NSString *)tableView:(UITableView *)tableView  
  94. titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath  
  95. //跳到指的row or section  
  96. [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO];  
  97.  
  98. 三、在UITableViewCell上建立UILable多行顯示  
  99.  
  100. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {  
  101.     static NSString *CellIdentifier = @"Cell";     
  102.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];  
  103.     if (cell == nil) {  
  104.         cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];  
  105.   UILabel *Datalabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 320, 44)];  
  106.   [Datalabel setTag:100];  
  107.   Datalabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;  
  108.   [cell.contentView addSubview:Datalabel];  
  109.   [Datalabel release];  
  110.  }   
  111.  UILabel *Datalabel = (UILabel *)[cell.contentView viewWithTag:100];  
  112.  [Datalabel setFont:[UIFont boldSystemFontOfSize:18]];  
  113.  Datalabel.text = [data.DataArray objectAtIndex:indexPath.row];  
  114.  cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;  
  115.     return cell;  
  116. }  
  117.  
  118. //選中cell時(shí)的顏色  
  119.  
  120. typedef enum {  
  121.     UITableViewCellSelectionStyleNone,  
  122.     UITableViewCellSelectionStyleBlue,  
  123.     UITableViewCellSelectionStyleGray  
  124. } UITableViewCellSelectionStyle   
  125.  
  126. //cell右邊按鈕格式  
  127.  
  128. typedef enum {  
  129.     UITableViewCellAccessoryNone,                   // don't show any accessory view  
  130.     UITableViewCellAccessoryDisclosureIndicator,    // regular chevron. doesn't track  
  131.     UITableViewCellAccessoryDetailDisclosureButton, // blue button w/ chevron. tracks  
  132.     UITableViewCellAccessoryCheckmark               // checkmark. doesn't track  
  133. } UITableViewCellAccessoryType   
  134. //是否加換行線  
  135.  
  136. typedef enum {  
  137.     UITableViewCellSeparatorStyleNone,  
  138.     UITableViewCellSeparatorStyleSingleLine  
  139. } UITableViewCellSeparatorStyle//改變換行線顏色  
  140.  
  141. tableView.separatorColor = [UIColor blueColor]; 

小結(jié):iPhone應(yīng)用開發(fā) UITableView學(xué)習(xí)點(diǎn)滴詳解的內(nèi)容介紹完了,希望本文對(duì)你有所幫助!

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

2011-08-08 10:10:14

iPhone開發(fā) 圖片 方法

2011-08-05 14:48:06

iPhone應(yīng)用 異步隊(duì)列

2011-07-27 10:13:23

Cocos2D iPhone

2011-08-15 13:44:07

iPhone開發(fā)UITableView

2011-08-02 17:14:41

iPhone應(yīng)用 UITableVie

2011-07-27 11:19:33

iPhone UITableVie

2011-08-09 17:29:29

iPhone文件屏幕

2011-08-10 17:37:00

iPhoneASIHTTPRequ

2011-07-28 15:11:23

iOS Objective-

2011-08-08 14:57:46

iPhone Autoreleas Property

2011-08-18 10:39:46

iPhone開發(fā)界面

2011-08-12 14:33:06

iPhone緩存文件

2011-08-15 11:37:20

iPhone開發(fā)Mask

2011-08-11 18:07:55

iPhoneQuratz 2D

2011-07-26 09:41:23

iPhone xcode Mac OS X

2011-08-12 10:04:24

iPhone開發(fā)視圖

2011-08-17 15:19:38

iPhone應(yīng)用數(shù)據(jù)

2011-08-09 17:12:30

iPhoneCFRunLoop

2011-08-15 17:38:48

iPhone開發(fā)調(diào)試工具

2011-07-06 14:53:14

點(diǎn)贊
收藏

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