Problem in UITableView custom cell?

If you want to have custom cells, I recommend you subclass UITableViewCell. In the example code you have given, you are creating a new label every single time the tableview asks for the cell for a row at an index path. While you are autoreleasing them, you are also adding them the the contentview of the cell, which increases their retain count and ensures that their lifetime is as long as the tableview's As cells are reused, you will continue to add more and more labels to it's content view, until you eventually run out of memory As far as the strange text output, it looks like you are adding a UILabel to one of your string with format calls If you were to do something like the code below, you would see something similar UILabel *label = UILabel alloc init NSLog(@"%@", label) label release Edit: Seeing your edited screenshot, I'm assuming you scrolled down to the 'S' section.In which case, you are seeing the labels on top of other labels.

Like I mentioned, you are creating a new label every time and putting it on top of the label you created the first (and second, third, etc) time you used the cell.

If you want to have custom cells, I recommend you subclass UITableViewCell. In the example code you have given, you are creating a new label every single time the tableview asks for the cell for a row at an index path. While you are autoreleasing them, you are also adding them the the contentview of the cell, which increases their retain count and ensures that their lifetime is as long as the tableview's.As cells are reused, you will continue to add more and more labels to it's content view, until you eventually run out of memory.

As far as the strange text output, it looks like you are adding a UILabel to one of your string with format calls. If you were to do something like the code below, you would see something similar. UILabel *label = UILabel alloc init; NSLog(@"%@", label); label release; Edit: Seeing your edited screenshot, I'm assuming you scrolled down to the 'S' section.

In which case, you are seeing the labels on top of other labels. Like I mentioned, you are creating a new label every time and putting it on top of the label you created the first (and second, third, etc) time you used the cell.

Thanks for the reply Jerry..if you won't mind can you please help me how to solve this problem of readding the labels..I am a newbie to this programming..I am learning now..so any input from you will be greatly helpful. – racharambola Aug 23 '10 at 18:39 1 I almost always subclass UITableViewCell for custom cells, but that a look at this article from apple (developer.apple. Com/iphone/library/documentation/userexperience/…).

It has great sample code for adding subviews to UITableViewCell in a manner very similar to the way you are doing it now. They add a custom label when instantiating a cell, and give it a tag. They then use this tag to get the label for reuse.

– Jerry Jones Aug 23 '10 at 19:06.

The reason you are getting the UILabel:... items showing up is the last line of the method, where you set the cell.textLabel.text. You don't want to do this if you are creating the cell with your own fields inside it.

I am just wondering if somehow that frame size width is not correct. You might want to step through the code and watch what happens with the firstLabel frame, especially before and after the sizeToFit call. – BP.

Aug 24 '10 at 13:07 Thanks for the reply BP..yup it works fine..the problem is with the stringWithFormat..The memory is autoreleased but the objects are not freed from the autorelease pool and as a result whenever I add the labels to the content view the labels get stacked on one other..If I won't add the label to the content view and assign the text to the cell label it works perfectly fine but I want to add the labels to content view so that I can access these labels later with a tag..please help..I am not finding a way to come out of it.. – racharambola Aug 24 '10 at 14:31 hey BP I solved the problem..I referred to the link given by Jerry Jones. Thank you for your replies.. – racharambola Aug 24 '10 at 15:09.

NSString *result=NSString stringWithFormat:@"%@ %@",contactText,sugarLabel should read: NSString *result=NSString stringWithFormat:@"%@ %@",contactText,sugarLabel. Text You are passing in an UILabel and not a NSString edit Try to instantiate and add UILabels only in the if (cell == nil) { block. While accessing labels properties and writing to it outside this block is ok.

Please see the edited method and updated screenshot..I want sugarLabel to be hidden..i.e. Its values should not be displayed on the table cell..will set Please help – racharambola Aug 23 '10 at 18:26 Please refer to screenshot 1 – racharambola Aug 23 '10 at 18:32 So you should not add sugarLabel. Text to a string, that will be displayed in another label – vikingosegundo Aug 23 '10 at 18:37 yup I did that viking..thanks for helping me..but somehow I am adding label one after another..I just updated the screenshot to figure 2 – racharambola Aug 23 '10 at 18:40 I tried to do this but some cells are not being displayed on the table..I am seeing an empty cell.. if (cell == nil) { firstLabel=UILabel allocinitWithFrame:CGRectMake(10, 10, 300, 40); sugarLabel = UILabel alloc initWithFrame: CGRectMake(10+firstLabel.frame.size.

Width+2, 10, 300, 60); cell = UITableViewCell alloc initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier autorelease; } – racharambola Aug 23 '10 at 19:02.

If you want to have custom cells, I recommend you subclass UITableViewCell. In the example code you have given, you are creating a new label every single time the tableview asks for the cell for a row at an index path. While you are autoreleasing them, you are also adding them the the contentview of the cell, which increases their retain count and ensures that their lifetime is as long as the tableview's.

As cells are reused, you will continue to add more and more labels to it's content view, until you eventually run out of memory. As far as the strange text output, it looks like you are adding a UILabel to one of your string with format calls. If you were to do something like the code below, you would see something similar.

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