2

セパレータースタイルに UITableViewCellSeparatorStyleSingleLine を使用して 'UITableViewStylePlain' として構成された UITableView があります。セルには背景色があります。

問題は、テーブルビューをスクロールすると、一部のセルが画面から消えて元に戻ると、セパレーターが表示されなくなることです。

セルは次のものに登録されます。

[tableView registerNib:nib forCellReuseIdentifier:cellIdentifier];

セル コード:

- (void)customizeMyTable
{
    [self.tableView setDataSource:self];
    [self.tableView setDelegate:self];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;

    NSString *cellIdentifier = [MyTableViewCell cellIdentifier];
    UINib *nib = [UINib nibWithNibName:cellIdentifier bundle:nil];

    [self.tableView registerNib:nib forCellReuseIdentifier:cellIdentifier];
    self.tableView.rowHeight = 50;
}

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyTableViewCell *cell = (MyTableViewCell*)[tableView dequeueReusableCellWithIdentifier:cellID];

    [cell configure:someDataForThisRow];

    return cell;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.backgroundColor = [UIColor lightGrayColor];
}

誰でもこの問題が発生しますか? これは、iOS 6 のテーブルビューではなく、iOS 5 でのみ発生するようです。

4

7 に答える 7

12

カスタムセルにlayoutSubviewsを実装し、対応するスーパーメソッドを誤って呼び出すのを忘れた場合、区切り線は表示されません。

たぶん、他のメソッドでスーパーを呼び出すのを忘れていないかどうかを確認する必要があります。

- (void)layoutSubviews
{
    [super layoutSubviews]; //<-THIS LINE YOU NEED

    //own code continues here
}
于 2012-11-15T21:54:59.953 に答える