【问题标题】:How to display Summation in TableView in iPhone SDK?如何在 iPhone SDK 的 TableView 中显示 Summation?
【发布时间】:2011-02-17 03:52:01
【问题描述】:

是否可以在 TableView 中显示屏幕截图中给出的信息?

这里:“MyFund”是 Rob、Mike 和 Sam Fund 的金额之和。

我不确定如何汇总金额并在表格标题中显示。

请帮忙!

【问题讨论】:

    标签: iphone objective-c cocoa-touch iphone-sdk-3.0 ios4


    【解决方案1】:

    嗯。我想你可以这样计算sectionIndexTitlesForTableView 中的总和:

    - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
    {
       // replace the following with however you'll calculate the sums
       int sumSectionOne = 4;
       int sumSectionTwo = 3;
    
       return [NSArray arrayWithObjects:[NSString stringWithFormat:@"$%d",sumSectionOne], [NSString stringWithFormat:@"$%d",sumSectionTwo], nil];
    }
    

    但这确实意味着您将在该表视图上调用reloadSections 很多。此外,这并不完全是 UITableView 的预期目的(尽管公认这是一种非常简单的方法)。

    【讨论】:

      【解决方案2】:

      你需要实现一个好的存储数据结构然后一个逻辑来获取它们。所以这一切都与逻辑有关,请参阅我的方法。

      您需要以字典形式将此记录添加到数组中,即在字典中添加资金和资金,其中两个不同的键分别为“资金”和“资金”(任何东西)。

      当您在titleForHeaderInSection 方法中创建部分表示时,您需要实现逻辑。您需要循环到数组计数并访问字典并添加所有“金钱”值。

      现在您需要实现。如果您在代码中遇到任何问题,请再次询问。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-24
        • 1970-01-01
        • 2013-01-01
        • 1970-01-01
        • 2012-08-04
        • 1970-01-01
        相关资源
        最近更新 更多