【问题标题】:How do I append a dollar sign to my sectionIndexTitlesForTableView?如何将美元符号附加到我的 sectionIndexTitlesForTableView?
【发布时间】:2011-08-13 18:36:36
【问题描述】:

我正在开发一个应用程序,该应用程序按美元数字显示核心数据表中的条目。我按美元数字属性对表格进行了排序。我也用它作为表索引的基础。

起初我为我的表格部分字符串制作了标题。但这没有用。我的表索引排序如下:

10 美元

100 美元

25 美元

5 美元

50 美元

而不是这个:

5 美元

10 美元

25 美元

50 美元

100 美元

所以我改变了我的模型,使节名属性成为一个整数。我填充了数据库,它们排序正确:

5

10

25

50

100

现在我只需将美元符号附加到部分索引标题。

我以为我会做这样的事情......

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {

    NSArray *frcSectionTitlesArray = [fetchedResultsController sectionIndexTitles];

    NSString *dollarSectionName = [NSString stringWithFormat:@"$%f", frcSectionTitlesArray];

    return dollarSectionName;

}

但这当然行不通,因为我处理的是数组,而不是字符串。

有什么想法吗?

【问题讨论】:

  • 不清楚你已经尝试了什么;我认为这应该可行。
  • @jtbandes,他在一个需要 NSArray 的方法中返回一个 NSString,这是一个很大的线索,它不会起作用。

标签: iphone core-data table-index


【解决方案1】:

试试这个:

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {

    NSArray * frcSectionTitlesArray = [fetchedResultsController sectionIndexTitles];
    NSMutableArray *newTitles = [[NSMutableArray alloc] unit];
    for (NSString *title in frcSectionTitlesArray) {
        [newTitles addObject:[NSString stringWithFormat:@"$%@", title]];
    }

    return [newTitles autorelease];

}

它遍历每个标题并将一个美元符号添加到一个新字符串中,并将其添加到一个新数组中,然后返回。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-22
    • 1970-01-01
    • 1970-01-01
    • 2021-07-11
    • 2011-04-15
    • 2021-12-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多