2010-05-18 85 views

回答

12

您可以定義IB定製的電池,其中將包含3個標籤和功能:

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

     static NSString *DetailCellIdentifier = @"DetailCell"; 

     UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:DetailCellIdentifier]; 

     if (cell == nil) { 
      NSArray *cellObjects = [[NSBundle mainBundle] loadNibNamed:@"DetailCell" owner:self options:nil]; 
      cell = (UITableViewCell*) [cellObjects objectAtIndex:0]; 
     } 

     // setup your cell 
    } 

當你定義在IB細胞給每個標籤的標記,所以當你需要把一個文本那麼你可以通過這樣的標籤檢索它:

 label = (UILabel *)[cell viewWithTag:NAME_TAG]; 
     label.text = myObject.name; 

並用其他2個標籤重複此操作。該標籤是唯一的編號。

將這個代碼,而不是//設置你的評論

+0

我創建了一個名爲「DetailCell」的自定義UIView子類,並在其上添加三個標籤。在 員工詳細信息UIView子類的tableview上添加上面的代碼。運行它,它不會在tabelView上顯示任何標籤。 – 2010-05-18 12:26:58

+1

如果你在IB中創建它,你應該創建一個UITableViewCell,而不是UIView.See這個鏈接詳細地創建自定義單元格: http://developer.apple。COM/iphone /庫/文件/ UserExperience /概念/ TableView_iPhone/TableViewCells/TableViewCells.html – 2010-05-18 14:54:13

0

創建包含,比方說一個定製UIView子類,三種UILabel元素作爲子視圖。然後將單元的contentView屬性設置爲此自定義視圖。

0

添加三個標籤作爲子viewsinto的UITableView細胞的content.then分配apprrpriate值,它 例如:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 


} 

//frame should be set accordingly(means should be framed accordingly). 

UILabel *l1=[[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 100,100)]; 

UILabel *l2=[[UILabel alloc]initWithFrame:CGRectMake(110,10,100,80)]; 
UILabel *l3=[[UILabel alloc]initWithFrame:CGRectMake(115,60,100,50)]; 

[cell.contentView addSubview:l1]; 
[cell.contentView addSubview:l2]; 
[cell.contentView addSubview:l3]; 
return cell; 
} 
+0

這不是一個好approche做必要的事情看上面的回答是正確的approche做的事情做 – 2012-04-12 12:46:08

2

我創建UIGridView。我相信你的問題可以用同樣的技術來解決。

您可以瞭解UIGridView的源代碼。代碼非常短。

+0

編譯它在iPhone上4 - 它真的滯後了...... – 2012-04-23 08:12:49

+0

你有多少個細胞? – Tanin 2012-05-04 13:36:57

+0

默認單元數 - 4列x 9行。只是編譯下載的示例項目到設備,它真的滯後。 – 2012-05-05 15:55:54