2012-11-11 61 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

相关问题