Buggish behavior of a UILabel Text when selecting a Custom built UITableViewCell: the text get mixup or overlaid with a previously loaded label?

The problem is that you create new label and add it to cell each time cell is being reused. To fix that you must create your label only when your cell is created.

The problem is that you create new label and add it to cell each time cell is being reused. To fix that you must create your label only when your cell is created: if (cell == nil){ cell = UITableViewCell alloc initWithFrame:CGRectZero reuseIdentifier: CellIdentifier autorelease; CGRect textViewRect = CGRectMake(10.0, 0.0, 250, 25); UILabel *textView = UILabel alloc initWithFrame:textViewRect; textView. Tag = kLabelTag; textView.

Font = UIFont systemFontOfSize:12.0; textView. TextColor = UIColor blackColor; textView. GhlightedTextColor = UIColor whiteColor; textView.

TextAlignment = UITextAlignmentRight; cell. ContentView addSubview:textView; textView release; CGRect imageRect = CGRectMake(270.0, 15, 16, 16); UIImageView *icon = UIImageView alloc initWithFrame:imageRect; icon. Image = myDictionary objectForKey:@"color-icon"; icon.

GhlightedImage = myDictionary objectForKey:@"gray-icon"; cell. ContentView addSubview:icon; icon release; } And after that you can get your label from cell using tag property you've assigned: UILabel *textView = (UILabel*)cell. ContentView viewWithTag:kLabelTag; textView.

Text = myDictionary objectForKey:@"name"; same logic also applies to setting up your icon imageview if it varies in different cells Also have a look at components standard UITableViewCell already provides (depending on its cell style) - there's already UIImageView and UILabels there and you can set your custom properties to them and use them without creating extra components.

Thanks for replying so fast, but that really does not work for me. I added the tag and tried to retrieve the label from the view with the tag if it reuses a previous cell. And some cell seems to work fine, but other have "black-out" label.

And player around with the table will quickly give a SegF with a "message sent to deallocated instance 0x69210c0". It sounds normal to me that this doesn't work as I am release all the label anyways... but I am a newby in iOS dev... so I am surely missing something – Alex Nov 29 '10 at 11:36 How woah... ok found the pb, I don't know how I missed that... You were right Vladimir, sorry for my misunderstanding. I don't even need to use the tags, I never realized that I was not supposed to re-create the cell every time.

That the identifier was smart enough to know it was the correct cell rather that the same "cell type". I basically should only create my subviews once if cell == nil and that's it. – Alex Nov 29 '10 at 11:43 yes, exactly :) – Vladimir Nov 29 '10 at 11:47 Thanks for your help!

It makes much more sense now :) – Alex Nov 29 '10 at 11:52.

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