Guillaume
Guillaume

Reputation: 393

UITableViewCell not shown

I try to draw and redraw my UITableView dynamically but when dynamically but my cells are not displayed (except the last one).

I stored my UITableViewCell in an array and found out that my cells have the same hexa addresses (0xa647f80 and 0xa64cbf0) that's why I guess my table reserved the space but don't diplay the cell

Here is a part of my array:

(
    (
        "<CriteriaAdvancedSubmenuCell: 0xa647f80; baseClass = UITableViewCell; frame = (0 0; 320 44); layer = <CALayer: 0xa610c60>>",
        "<CriteriaAdvancedSubmenuCell: 0xa64cbf0; baseClass = UITableViewCell; frame = (0 0; 320 44); layer = <CALayer: 0xa63c4f0>>"
    ),
        (
        "<CriteriaAdvancedSubmenuCell: 0xa647f80; baseClass = UITableViewCell; frame = (0 0; 320 44); layer = <CALayer: 0xa610c60>>",
        "<CriteriaAdvancedSubmenuCell: 0xa64cbf0; baseClass = UITableViewCell; frame = (0 0; 320 44); layer = <CALayer: 0xa63c4f0>>"
    ),
        (
        "<CriteriaAdvancedSubmenuCell: 0xa647f80; baseClass = UITableViewCell; frame = (0 0; 320 44); layer = <CALayer: 0xa610c60>>",
        "<CriteriaAdvancedSubmenuCell: 0xa64cbf0; baseClass = UITableViewCell; frame = (0 0; 320 44); layer = <CALayer: 0xa63c4f0>>"
    )
)

And here is how I instanciate my cells:

static NSString *cellID = @"criteriaAdvancedSelectionCustomCell";

CriteriaAdvancedSubmenuCell *cell = (CriteriaAdvancedSubmenuCell *) [tableView dequeueReusableCellWithIdentifier:cellID];

if (cell == nil)
{
    cell = (CriteriaAdvancedSubmenuCell *) [tableView dequeueReusableCellWithIdentifier:cellID];
}
else
{
    [cell prepareForReuse];
}

Please help me, I'm becoming crazy!

Thanks :)

Upvotes: 0

Views: 95

Answers (1)

J&#246;rg Kirchhof
J&#246;rg Kirchhof

Reputation: 1640

if (cell == nil)
{
    cell = (CriteriaAdvancedSubmenuCell *) [tableView dequeueReusableCellWithIdentifier:cellID];
}

You are telling your TVC to reuse a cell that doesn't exist yet.

Try replacing the if-part like this (you may need to change the UITableViewCellStyleDefault part):

if (cell == nil) {
    cell = [[CriteriaAdvancedSubmenuCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                              reuseIdentifier:@"criteriaAdvancedSelectionCustomCell"];
}

Upvotes: 1

Related Questions