偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

iPhone開(kāi)發(fā)應(yīng)用中關(guān)于UITableView詳細(xì)教程

移動(dòng)開(kāi)發(fā) iOS
本文主要是來(lái)學(xué)習(xí)UITableView的詳細(xì)操作。UITableView是一個(gè)很強(qiáng)大的控件,在我們iphone開(kāi)發(fā)過(guò)程中會(huì)經(jīng)常用到。

iPhone開(kāi)發(fā)應(yīng)用中關(guān)于UITableView詳細(xì)教程是本文要介紹的內(nèi)容,主要是來(lái)學(xué)習(xí)UITableView的詳細(xì)操作。UITableView是一個(gè)很強(qiáng)大的控件,在我們iphone開(kāi)發(fā)過(guò)程中會(huì)經(jīng)常用到。

下面我做以下簡(jiǎn)單介紹

‍UITableView有一個(gè)基本元素的索引NSIndexPath,你可以通過(guò)索引NSIndexPath找到‍UITableView下面的子元素只要這個(gè)方法

  1. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath  
  2.    //在這個(gè)方法里你可以根據(jù)NSIndexPath判斷相應(yīng)的元素,然后做處理 

例如:

  1. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath  
  2. {  
  3. if(indexPath.section == 5 && indexPath.row ==2)return;  
  4. }  
  5. UITableView的每一個(gè)子元素(Entity)稱為UITableViewCell,UITableViewCell由下面這個(gè)方法初始化  
  6. -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath  
  7. //這個(gè)方法是必需的,他是產(chǎn)生UITableView內(nèi)容的必須載體 

例如:

  1. -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath  
  2. {//因?yàn)閁ITableView由很好的內(nèi)存控制機(jī)制,他每次只加載一屏幕的cell(7個(gè)左右),當(dāng)用戶觸摸移動(dòng)時(shí),動(dòng)態(tài)加載新產(chǎn)生的cell  
  3. static NSString *RootViewControllerCell =@"HelpViewControllerCell";//產(chǎn)生一個(gè)靜態(tài)標(biāo)識(shí)  
  4. UITableViewCell* cell =(UITableViewCell*)[tableViewdequeueReusableCellWithIdentifier:RootViewControllerCell];//標(biāo)記新產(chǎn)生的cell  
  5. if(cell==nil) //如果cell不為空標(biāo)識(shí)cell還沒(méi)有被釋放,還在屏幕中顯示  
  6. {  
  7. cell =[[[UITableViewCellalloc]initWithStyle:UITableViewCellSeparatorStyleSingleLinereuseIdentifier:RootViewControllerCell]autorelease];  
  8. }  
  9. return cell;  
  10. } 

UITableViewCell通過(guò)NSIndexPath索引,正如上面所看到的,NSIndexPath索引由兩個(gè)屬性section和row

section通常就是我們所謂的段,row所謂的段內(nèi)的行

我們可以通過(guò)下面這個(gè)方法返回你想要在UITableView中顯示段數(shù)

  1. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; //通常情況下我們看到的都是一段,左移這個(gè)方法不是必須的 

我們可以通過(guò)下面這個(gè)方法返回你想要在UITableView中的某一段中顯示的行數(shù)

  1. - (NSInteger)tableView:(UITableView *)tView numberOfRowsInSection:(NSInteger)section;//通常情況下是一段,所以不必判斷段數(shù) 

假如您有很多段,而且每一個(gè)段的顯示行數(shù)還不一樣,你就要通過(guò)上面的方法精確控制,例如:

  1. - (NSInteger)tableView:(UITableView *)tView numberOfRowsInSection:(NSInteger)section {  
  2.       if(section == 0) return 1;  
  3.       if(section == 1) return 1;  
  4.    if(section == 2) return 8;  
  5.    if(section == 3) return 1;  
  6.    if(section == 4 || section ==5)   return 3;  
  7.    if(section == 6)return 4;  
  8.    return0;  

這個(gè)方法時(shí)必須的。

另外我們可以通過(guò)下面這個(gè)方法精確控制某一行的高度

  1. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {  
  2.  
  3.    if(indexPath.section == 0 && indexPath.row ==0)    return80;  
  4.    return 40.0;  

另外我們可以通過(guò)下面這個(gè)方法精確控制某一段的高度

  1. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section  
  2. {  
  3.    if (section == 0)return60.0;  
  4.    return40.0;  

另外我們還可以通過(guò)下面這個(gè)方法精確控制某一段的標(biāo)題和視圖

  1. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;  
  2.  
  3. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section; 

這兩個(gè)方法鄙視必須的,我就不作介紹。

擁有以上的及格方法你就可以完成超炫的UITableView視圖了。前提是要活靈活用,還有其他幾個(gè)常用的控件,這里就不在寫(xiě)了,需要的可以留言交流。

小結(jié):iPhone開(kāi)發(fā)應(yīng)用中關(guān)于UITableView詳細(xì)教程的內(nèi)容介紹完了,希望本文對(duì)你有所幫助!

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

2011-08-02 17:14:41

iPhone應(yīng)用 UITableVie

2011-07-27 11:14:37

iPhone UITableVie

2011-08-09 17:12:30

iPhoneCFRunLoop

2011-07-06 17:40:43

iPhone SDK

2011-07-08 14:58:16

iPhone Xcode iOS

2011-08-18 10:39:46

iPhone開(kāi)發(fā)界面

2011-08-08 14:07:49

iPhone開(kāi)發(fā) 字體

2011-08-12 10:09:23

iPhone開(kāi)發(fā)多線程

2011-07-27 11:19:33

iPhone UITableVie

2011-08-09 13:10:32

iPhone地圖開(kāi)發(fā)

2011-08-19 10:35:19

iPhone應(yīng)用Three20

2011-08-18 10:06:10

2011-08-10 10:23:20

iPhoneArchivingNSCoder

2011-08-08 18:19:09

iPhone音頻播放

2011-08-09 14:42:07

iPhonePCM播放器

2011-07-29 13:27:48

iPhone 開(kāi)發(fā) Nib

2011-08-10 17:37:00

iPhoneASIHTTPRequ

2011-08-18 15:24:40

iPhone國(guó)際化

2011-08-22 14:21:24

iPhone開(kāi)發(fā)UIView Anim

2011-08-22 15:15:49

iPhone開(kāi)發(fā)NSMutableAr排序
點(diǎn)贊
收藏

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