【问题标题】:TableView cells with double values具有双值的 TableView 单元格
【发布时间】:2011-08-12 21:03:54
【问题描述】:

我有一个 tableView,自定义单元格由 NSMutableDictionaries 填充,位于 NSMutableArray 内。

现在,我想检查valueForKey@"Location" 中当前正在填充的单元格上方的单元格。因为,如果那个位置是相同的,那么下面的那个单元格应该留下一些标签 blanco。

例如:

[Thing on location: Building A  has problem X]
[       and problem Y ]  
[Thing on location: Building B  has problem X]

(是的,我知道,一张糟糕的“绘图”表格,哈哈)。

无论如何,在cellForRowAtIndexPath 我已经尝试过代码:

if ((indexPath.row - 1) > -1)
    {
        NSString *eerste = [[NSString alloc] initWithFormat:@"%@", [[lijstErrors objectAtIndex:(indexPath.row - 1)] objectForKey:@"Location"]];
        NSString *tweede = [[NSString alloc] initWithFormat:@"%@", [incInRow objectForKey:@"Location"]];
        NSLog(@"Comparing %@ met %@", eerste, tweede);
    }

问题是,它永远不会被调用。我的猜测是,每次填充单元格时都不会调用cellForRowAtIndexPath?有什么提示吗?

【问题讨论】:

  • 你能在 if 语句之前转储indexPath.row 吗?然后滚动,这看起来是正确的,仍然没有人知道......

标签: ios objective-c xcode uitableview cell


【解决方案1】:

应该这样调用,否则可能是你忘记设置数据源了。然后试试

myTableView.dataSource =self;

试试下面的:

if ((indexPath.row - 1) >= -1)

【讨论】:

    【解决方案2】:

    不,每次绘制单元格时都会调用它。将 tableView 的委托设置为托管 tableview 的实例:在大多数情况下它是自己的。

    【讨论】:

    • 这样就可以正确查看表格了。但是,我在第一篇文章中提到的 NSLog 从未被调用过。如果我放置一个新的 NSLog(@"Test");在它上面,测试被记录但不是比较:(有什么想法吗?
    • 啊你的意思是if ((indexPath.row - 1) > -1)?我想我误会了我认为这里有一些根本性的问题。
    • 是的,那个没有被记录,但是当我停止测试负数时它就解决了!感谢您的反馈:)
    • 你设置了数据源吗?
    猜你喜欢
    • 2014-07-22
    • 1970-01-01
    • 2013-01-23
    • 2018-12-25
    • 2012-09-12
    • 2017-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多