views:

65

answers:

2

Hi guys,

For quite a bit of time I am struggled with a kinda stupid problem. Hope someone can give me a hand.

UITableView is being implemented. The UITableViewCell is drawn in .xib and connected to a textEditCell property.

in the main program there is a simple code:

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

return textEditCell;

}

Yet when the view is drawn, only some cells (after the view is started - last cell) is drawn. If the view is dragged beyond the top end of the screen, the top cell is been drawn, the bottom one is gone; when dragging to the bottom the behaviour is opposite.

Given the example in Apple cookbook? that is Listing 5-7. what am I doing wrong?

Appreciate your help.

A: 

Basically you're creating a single instance of a cell and trying to assign it to many rows. In the Apple cookbook you have a fixed number of custom cells, called cell0, cell1 instanced separately in the builder.

You would need to create another nib file to create your cells. Also remember about reusing cells - otherwise you will definitely have memory problems.

Estarriol
Estarriol, thanks for the answer. Creating another nib seems to be the only way; though it doesn't seem to be logical - why can't I have them all in one nib? I'm not mentioning that nib is loaded for every cell - that is a redundant operation, isn't it?Another question is: where is a new instance of the reused cell created in, for example, http://stackoverflow.com/questions/202471/is-it-possible-to-design-nscell-subclasses-in-interface-builder ?Or the newly reloaded nib gives a new object?
DNK
+1  A: 

What is described in Listing 5-7 only works if you only have one cell of that kind in your table. If you need many copies of that same cell then you should use the technique described in Listing 5-5.

St3fan