1

我正在使用故事板来制作静态表格视图。一切正常!

现在我想自定义表格视图单元格。

所以我添加了一个 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;
}

但是如果我现在运行应用程序,表格视图是空的,并且没有自定义背景......

有人可以帮助我吗?:=)

劳伦兹

4

1 回答 1

0

有两种方法可以为您的tableview:static单元格和动态原型设置单元格。实际上,对于静态单元格模式,您可以直接在 IB 中设置单元格的背景颜色。

如果您想使用cellForRowAtIndexPath方法来自定义您的单元格,您应该实现所有非可选方法,例如:numberOfRowsInSection cellForRowAtIndexPath

于 2013-01-02T06:35:39.500 回答