Domanda

I am using prototype cell to calculate real cell height. Since I'm using storyboard I have chosen to create prototype cell by dequeing it. Example code:

- (MyCell *)prototypePriceOptionCell
{
    if (_prototypeCell == nil) {
        _prototypeCell = (MyCell *)[self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    }
    return _prototypePriceOptionCell;
}

This prototype is never returned to tableView in cellForRowAtIndexPath method.

Will it be dequed by table view to reuse and show it in table view?

È stato utile?

Soluzione

You technically could, from the docs:

If you registered a class for the specified identifier and a new cell must be created, this method initializes the cell by calling its initWithStyle:reuseIdentifier: method. For nib-based cells, this method loads the cell object from the provided nib file. If an existing cell was available for reuse, this method calls the cell’s prepareForReuse method instead.

But it also states that it can return nil under some circumstances. However, I wouldn't use your approach, not because it wouldn't work but because it's not supposed to be used like that. This means that you have weak code relying on a feature it's not supposed to be used like that.

My suggestion, instantiate your cell manually calling the appropriate methods. Also, I like to have my cells on separate xibs, away from storyboards.

Edit: Answering your question at the end, yes, the cell can and will be dequeued by the table view if you call dequeue in your cellForRowAtIndexPath

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top