How should I addSubview to cell.contentView?

It's all about performance. With A, you reuse the cell with all of its subviews, with B, you reuse only the raw cell and add a new subview every iteration, which IMHO is not as good as A re: performance I say either create a UITableView subclass or use solution A.

It's all about performance. With A, you reuse the cell with all of its subviews, with B, you reuse only the raw cell and add a new subview every iteration, which IMHO is not as good as A re: performance. I say either create a UITableView subclass or use solution A.

– ohho Aug 16 '10 at 3:52 @ohho, Don't think so. Everything looks fine to me. – Jacob Relkin Aug 16 '10 at 3:56 Wouldn't B keep adding labels to the cell?

I think after some scrolling, you'd end up with multiple cells holding multiple labels in their subviews. Please correct me if I'm wrong. – noroom Oct 9 '10 at 16:50.

You should only add the sub views when you create the cell as in A, however assign the values to the labels etc every time as in B. This solution would fall out naturally if you create your own subclass of UITableViewCell that adds it's own sub views. Something like this.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = tableView dequeueReusableCellWithIdentifier:CellIdentifier; if (cell == nil) { cell = UITableViewCell alloc initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier autorelease; CGRect frame = CGRectMake(0, 0, 160, 50); UILabel *label = UILabel alloc initWithFrame:frame; label. TextAlignment = UITextAlignmentRight; cell. ContentView addSubview:label; label release; } // Get a reference to the label here label.

Text = @"9:00am"; return cell; } This way you get the performance benefits of only allocating the sub views once and you can just set the appropriate properties on the subview as needed.

Thanks Gary. My project does not involve any UITableViewCell yet. Could you please elaborate more on your second sentence?

– ohho Aug 16 '10 at 4:01.

You should only add the sub views when you create the cell as in A, however assign the values to the labels etc every time as in B. This solution would fall out naturally if you create your own subclass of UITableViewCell that adds it's own sub views. Something like this.

This way you get the performance benefits of only allocating the sub views once and you can just set the appropriate properties on the subview as needed.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions