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

iPhone開發(fā)中關(guān)于Xib文件創(chuàng)建UITableViewCell方法

移動開發(fā) iOS
本文介紹的是iPhone開發(fā)中關(guān)于Xib文件創(chuàng)建UITableViewCell方法,主要死來介紹使用Xib文件創(chuàng)建UITableViewCell幾種不同的方法,來看詳細(xì)內(nèi)容。

iPhone開發(fā)中關(guān)于Xib文件創(chuàng)建UITableViewCell是本文要介紹的內(nèi)容,主要是來學(xué)習(xí)如何使用XIB文件創(chuàng)建UITableViewCell的幾種方法,來看本文詳細(xì)內(nèi)容。

1、cell不做為controller的插口變量

首先創(chuàng)建一個空的xib文件,然后拖拽一個cell放在其上面,記得設(shè)置其屬性Identifier,假設(shè)設(shè)置為“mycell”,則我們在代碼中請求cell的時候就應(yīng)該如下寫:

  1.         NSString *identifier = @"mycell";  
  2. UITableViewCell *cell = [tView dequeueReusableCellWithIdentifier: identifier];  
  3. if (!cell) {  
  4.         cell = [[[NSBundle mainBundle] loadNibNamed:identifier owner:self options:nil] lastObject];  
  5.    }  
  6. return cell; 

2、cell做為controller的插口變量

聲明的時候應(yīng)該寫

  1. @property (nonnonatomic, assign) IBOutlet UITableViewCell *tvCell;   
  2. @synthesize tvCell  

創(chuàng)建nib文件的時候要把file owner選擇成當(dāng)前的controller,然后把IBOut連接起來。

cellForRowAtIndexPath函數(shù)實(shí)現(xiàn)為:

  1. static NSString *MyIdentifier = @"MyIdentifier";  
  2. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];  
  3. if (cell == nil) {  
  4. [[NSBundle mainBundle] loadNibNamed:@"TVCell" owner:self options:nil];  
  5. cell = tvCell;  
  6. self.tvCell = nil;  

我們可以通過UINib來提高性能

使用UINib類可以大大的提高性能,正常的nib 加載過程包括從硬盤讀取nib file,并且實(shí)例化對象。但是當(dāng)我們使用UINib類時,nib 文件只用從硬盤讀取一次,讀取之后,內(nèi)容存在內(nèi)存中。因?yàn)槠湓趦?nèi)存中,創(chuàng)建一序列的對象會花費(fèi)很少的時間,因?yàn)槠洳辉傩枰L問硬盤。

頭文件中:

  1.  ApplicationCell *tmpCell;  
  2. // referring to our xib-based UITableViewCell ('IndividualSubviewsBasedApplicationCell')  
  3. UINib *cellNib;  
  4. @property (nonnonatomic, retain) IBOutlet ApplicationCell *tmpCell;  
  5. @property (nonnonatomic, retain) UINib *cellNib; 

viewDidLoad中:

  1. self.cellNib = [UINib nibWithNibName:@"IndividualSubviewsBasedApplicationCell" bundle:nil]; 

cellForRowAtIndexPath實(shí)現(xiàn):

 

  1.  static NSString *CellIdentifier = @"ApplicationCell";  
  2.     ApplicationCell *cell = (ApplicationCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];  
  3.     if (cell == nil)  
  4.     {  
  5.  
  6.         [self.cellNib instantiateWithOwner:self options:nil];  
  7. cell = tmpCell;  
  8. self.tmpCell = nil;  
  9.     } 

小結(jié):iPhone開發(fā)中關(guān)于Xib文件創(chuàng)建UITableViewCell方法的內(nèi)容介紹完了,希望通過本文的學(xué)習(xí)能對你有所幫助!

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

2011-07-29 13:27:48

iPhone 開發(fā) Nib

2011-08-08 14:07:49

iPhone開發(fā) 字體

2011-08-16 18:56:11

iPhone開發(fā)Three20

2011-08-19 10:35:19

iPhone應(yīng)用Three20

2011-08-09 17:12:30

iPhoneCFRunLoop

2011-08-22 14:21:24

iPhone開發(fā)UIView Anim

2011-08-15 13:44:07

iPhone開發(fā)UITableView

2011-08-22 15:15:49

iPhone開發(fā)NSMutableAr排序

2011-03-16 11:22:16

iconDefaultiPhone

2011-08-12 14:33:06

iPhone緩存文件

2011-07-06 17:40:43

iPhone SDK

2011-07-19 15:33:57

iPhone

2011-08-18 10:39:46

iPhone開發(fā)界面

2011-07-20 15:42:18

iPhone 劃動條

2011-07-29 14:18:46

iPhone開發(fā) 動畫

2011-08-12 10:09:23

iPhone開發(fā)多線程

2011-08-05 10:13:45

iPhone開發(fā)工具 Cocoa Xcode

2011-08-09 14:42:07

iPhonePCM播放器

2011-08-22 11:49:20

iPhone文件系統(tǒng)NSFileManag

2011-07-08 14:09:51

iPhone UI
點(diǎn)贊
收藏

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