向下滚动时,IPhone Storyboard自定义单元格消失 [英] IPhone Storyboard custom cell disappears when scrolling down

查看:73
本文介绍了向下滚动时,IPhone Storyboard自定义单元格消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚完成了一个项目,我在Storyboard中为我的TableView使用自定义单元格。

I have just finished a project where I use a custom cell for my TableView in Storyboard.

问题是当我向下滚动每个单元格中的内容时在我的情况下是
两个标签。

The problem is that when i scroll down the content in each cell is gone, which in my case is two Labels.

这是我用来呈现每个单元格的代码:

This is the code I use to present each cell:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CustomCell";
    MessageCell *cell = (MessageCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[MessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    Message *messageForRow = (Message *)[messages objectAtIndex:[indexPath row]];
    [cell.messageLabel setText:[messageForRow message]];
    [cell.senderLabel setText:[messageForRow sender]];

    return cell;
}

我在storyboard中指定了正确的cellidentifier,并将Class链接到我的
自定义单元格类。

I have specified the right cellidentifier in storyboard and linked the Class to my custom cell class.

可能出错?如果有任何我错过的信息,请告诉我
告诉我。

What can be wrong? If there is any needed information I have missed to present, please tell me.

最好的考虑
Robert

Best regard Robert

推荐答案

我自己解决了,问题不在于更新方法。
错误地,我在Message类中使用弱签名。

I solved it by myself, the problem did not lie within the update method. By mistake I used the weak signature for the properties in my Message class.

@property (nonatomic, weak) NSString *sender;

我使用强签名解决了这个问题。

I solved it by using the strong signature instead.

@property (nonatomic, strong) NSString *sender;

这是一个很好的教训,因为我并不完全理解强大的概念
弱势。

This was a great lesson because I didn't fully understand the concept of strong and weak.

这篇关于向下滚动时,IPhone Storyboard自定义单元格消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆