首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >将数据发送到UITableViewCell -数据不会发送

将数据发送到UITableViewCell -数据不会发送
EN

Stack Overflow用户
提问于 2019-05-24 03:07:33
回答 1查看 27关注 0票数 0

每次我尝试向这个自定义的表视图单元格发送一个数组时,该数组都不发送(从array.count = 0可以看出,而它应该是9)。

这是我的cell.h

代码语言:javascript
复制
@interface Scell : UITableViewCell

...
@property (nonatomic, strong) NSMutableArray *lineInfo;

@end

cell.m

代码语言:javascript
复制
@implementation Scell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

    if (self)
    {
        self.lineInfo = [[NSMutableArray alloc]init];

        //set up labels here, etc.

        NSLog(@"Lines count: %li", self.lineInfo.count);
    }

    return self;
}

这是我尝试发送数据的地方。

setup.m

代码语言:javascript
复制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //Make cell 
    Scell *cell = (Scell *)[tableView dequeueReusableCellWithIdentifier:@"sCell" forIndexPath:indexPath];

    object *temp = [self.array objectAtIndex:indexPath.row];

    //labels, etc.

    NSLog(@"count: %li", temp.lineInfo.count);
    cell.lineInfo = temp.lineInfo;
    return cell;
}

你知道为什么它不能发送吗?setup.m中的NSLog显示9,但Scell中的显示为0。

EN

回答 1

Stack Overflow用户

发布于 2019-05-24 03:16:52

在cell.m中,当单元格初始化时,将打印行数,因此此时此数组中没有值,这就是它打印零的原因。

在setup.m中的cellForRowAtIndexPath中,temp的lineInfo被分配给单元格的lineInfo属性。因此,cellForRowAtIndexPath打印正确的计数,但initWithStyle显示0。

希望这能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56281538

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档