Custom UITableViewCell Created in StoryBoard Results in duplicated UILabels

I have been through many questions on SO before asking this.

I have an issue where i have created a custom UITableView cell in a StoryBoard. I have subclassed UITableViewCell and exposed properties to link my various components to within the cell.

I am NOT creating or adding any components to the cell in

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

I simply use the

[tableView dequeueReusableCellWithIdentifier:cleanseCell forIndexPath: indexPath];

call to reuse cells. I do some customisation on the cells but I don't add anything new. I just modify an image, some labels and a text field . The cell reuse identifier is set correctly both in the code and on the component in the storyboard.

The problem is that when the cell is reused, somewhere under the hood the UILabels are being duplicated. I have a UITextField in there as well - it doesn't have this problem. Only the UILabels are somehow duplicated.

So the cell presents fine the first time with the correct information. Then the next time the cell is created its still fine. The third time the cell shows up with Overlapping UILabels. One with the new text and one with the text of the original cell. At any rate there are two UILabels in the cell now where there was only one before and I didn't add it there.

Anyone else experienced this or have some comment to make?

EDIT:

This is my UITableViewCell - There is nothing in the implementation other than synthesising the properties (which is not even required anyway)

#import <UIKit/UIKit.h>

@interface SJCleanseNotificationCell : UITableViewCell
@property (nonatomic)float openHeight;
@property (nonatomic, strong)IBOutlet UIImageView *iconView;
@property (nonatomic, strong)IBOutlet UILabel *dateTimeLabel;
@property (nonatomic, strong)IBOutlet UILabel *titleLabel;
@property (nonatomic, strong)IBOutlet UITextView *messageLabel;
-(IBAction)dismiss:(id)sender;
-(IBAction)activate:(id)sender;
@end

And this is the cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cleanseCell = @"CleanseCell";

    NSDictionary *cleanse = sjTimer.cleanseNotification;

    SJCleanseNotificationCell *cell;
    if([_tableView respondsToSelector:@selector(dequeueReusableCellWithIdentifier:forIndexPath:)])
        cell = (SJCleanseNotificationCell*)[_tableView dequeueReusableCellWithIdentifier:cleanseCell forIndexPath: indexPath];
    else
        cell = (SJCleanseNotificationCell*)[_tableView dequeueReusableCellWithIdentifier:cleanseCell];

    [cell.dateTimeLabel setText:[cleanse objectForKey:@"date"]];
    [cell.titleLabel setText:[cleanse objectForKey:@"title"]];
    [cell.messageLabel setText:[cleanse objectForKey:@"message"]];
    NSNumber *stage = (NSNumber*)[cleanse objectForKey:@"stage"];
    if(stage)
       [cell.iconView setImage:[[SJCleanseTimer instance]bottleImageForCleanseStage:stage.integerValue]];
    cell.delegate = self;
    cell.openHeight = 100;
    return cell;
}

Answers


The problem was I had Clears Graphics Context unchecked in the inspector on the UILabel elements. After checking that checkbox it behaved normally.


Need Your Help

Creating a JavaScript Search of Arrays

javascript arrays search text

I'm new to these forums and very new to JavaScript. Since my school does not offer in depth JavaScript courses, I have tried to understand a lot of it on my own.

DataGridView Cell Alignment Won't Work

c# winforms datagridview styles alignment

I have a DataGridView that I use in a C# Winforms project. The grid does NOT autogenerate columns. I have manually set the column names and properties.