2009-09-10 62 views
0

我想在我的iPhone應用程序中創建一個表格視圖。在該表格中,每個圖像應包含1個圖像,一些文本行,一些符號等。我現在不瞭解如何定製我們的表的細胞。請您提供一些幫助,如果您有..iPhone中的單元格定製應用

回答

2

我想你可以使用默認的UITableViewCell做你所描述的通過與適當的UITableViewCellStyle初始化單元格(- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

如:

-(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]; 
} 

// Set up the cell... 

return cell; 

}

它給你: 「的樣式與在頂部和較小的灰色文本下方的左對齊的標籤左對齊的標籤細胞在IPO d應用程序使用這種風格的單元格。「 默認情況下,每種UITableViewCell都具有圖像屬性。

但這裏是構建定製單元一些教程:

Custom UITableViewCells with Interface Builder

http://iphone.zcentric.com/2008/08/05/custom-uitableviewcell/

2

您可以創建在Interface Builder中的單元格。從一個UITableViewCell開始,它像一個視圖,然後添加一個UIImage,一個或多個標籤,任何容器來容納你的符號等等。

然後在你的cellForRowAtIndexPath中加載nib並填入圖片和標籤,等等。

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

    static NSString *CellIdentifier = @"Cell"; 

    MyTableCell *cell = (MyTableCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) {  
     cell = myTableCell; // get the object from the outlet 
     myTableCell = nil; // make sure this can't be re-used accidentally 
    } 


    // Set up the cell... 
    cell.myViewController = self; 
    // set up image and labels here 
    return cell; 
} 
相關問題