0

嗨,我有一个 tableview 的问题。单元格文本标签(默认原型单元格)隐藏了我的部分背景。我不明白为什么以及如何改变。

我知道我可以修复放置自己的标签,但我想了解这里的错误在哪里。



应该是这样的,底部有一条线......作为分隔线

应该是这样的,底部有一条线......作为分隔线



但这就是它的结果

在此处输入图像描述



这是代码

- (void)viewDidLoad
{
    [super viewDidLoad];

    icons = [NSArray arrayWithObjects:
             @"No Icon",
             @"Appointments",
             @"Birthdays",
             @"Chores",
             @"Drinks",
             @"Folder",
             @"Groceries",
             @"Inbox",
             @"Photos",
             @"Trips",
             nil];

    rowImage = [NSArray arrayWithObjects:@"row", @"row2", @"row3", @"row4", nil];

    self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background"]];
    self.tableView.tableFooterView = [[UIView alloc] init];

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [icons count];
}

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"IconCell"];
    NSString *icon = [icons objectAtIndex:indexPath.row];

    cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[rowImage objectAtIndex:arc4random()%4]]];
    cell.textLabel.textColor = [UIColor redColor];
    cell.textLabel.bounds = CGRectMake(cell.textLabel.frame.origin.x, cell.textLabel.frame.origin.y, cell.textLabel.frame.size.width, 10);
    cell.textLabel.frame = CGRectMake(cell.textLabel.frame.origin.x, cell.textLabel.frame.origin.y, cell.textLabel.frame.size.width, 10);
    cell.textLabel.text = icon;
    cell.imageView.image = [UIImage imageNamed:icon];
    return cell;
}
4

1 回答 1

0

接下来试试:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.textLabel.backgroundColor = [UIColor clearColor];
}
于 2013-10-15T16:56:16.583 回答