在StoryBoard中创建的自定义UITableViewCell在重复的UILabel中生成结果

时间:2013-11-22 10:00:12

标签: ios objective-c uitableview

在问这个问题之前,我已经经历了很多关于SO的问题。

我有一个问题,我在StoryBoard中创建了一个自定义UITableView单元格。我已经将UITableViewCell和公开属性子类化,以将我的各种组件链接到单元格内。

我不是在

中创建或添加任何组件到单元格
- (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

我只是使用

[tableView dequeueReusableCellWithIdentifier:cleanseCell forIndexPath: indexPath];

调用重用单元格。我对单元格进行了一些自定义,但是我没有添加任何新内容。我只是修改图像,一些标签和文本字段。在代码中和故事板中的组件上都正确设置了单元重用标识符。

问题是,当细胞被重复使用时,UILabel正在重复使用。我也有一个UITextField - 它没有这个问题。只有UILabel在某种程度上是重复的。

因此第一次使用正确的信息细胞呈现良好状态。然后下一次创建单元格时它仍然很好。第三次单元格出现重叠UILabels。一个带有新文本,另一个带有原始单元格的文本。无论如何,单元格中有两个UILabel,之前只有一个,我没有在那里添加。

其他人是否经历过此或有过评论?

编辑:

这是我的UITableViewCell - 除了合成属性之外,实现中没有任何内容(无论如何都不需要)

#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

这是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;
}

1 个答案:

答案 0 :(得分:0)

问题是我在UILabel元素的检查器中未选中清除图形上下文。检查完该复选框后,它表现正常。