2012-11-11 62 views
1

我正在使用故事板來創建一個靜態tableview。 一切正常!自定義靜態TableView與故事板 - 單元格背景

現在我想自定義表格視圖單元格。

因此,我添加一個tableViewController並將其連接到故事板視圖。 這裏是我使用自定義代碼:

-- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

    // Configure the cell... 

    UIColor *color = [[UIColor alloc] initWithRed:0.0 green:0.0 blue:0.0 alpha:0.0]; 

    cell.detailTextLabel.backgroundColor = color; 

    cell.textLabel.backgroundColor = color; 

    cell.backgroundView = [ [UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"cellbackground.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0]]; 
    cell.selectedBackgroundView = [ [UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"cellbackground_down.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0]]; 

    return cell; 
} 

但如果我現在運行應用程序,表視圖是空的,沒有自定義背景...

一些能幫我嗎? :=)

Laurenz

回答

0

有兩種方法來設置你的tableview:static細胞&動態原型細胞。實際上,對於靜態單元格模式,您可以直接在IB中設置單元格的背景顏色。

如果你想使用cellForRowAtIndexPath方法來定製你的,你應該實現所有的非可選的方法,如:numberOfRowsInSectioncellForRowAtIndexPath

相關問題