1

I'm working on an app that displays entries in a Core Data table by dollar figure. I sorted my table by a dollar figure attribute. I also use that as the basis for the table index.

At first I made my titles for my table sections strings. But that didn't work. My table index would sort like this:

$10

$100

$25

$5

$50

Instead of this:

$5

$10

$25

$50

$100

So I changed my model to make the section name attribute an integer. I populated the database, and they sort correctly:

5

10

25

50

100

Now I just have to append a dollar sign to the section index title.

I thought I would do something like this...

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

    NSArray *frcSectionTitlesArray = [fetchedResultsController sectionIndexTitles];

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

    return dollarSectionName;

}

But of course that does't work because I'm dealing with an array, and not a string.

Any ideas?

RyeMAC3
  • 1,023
  • 1
  • 10
  • 17

1 Answers1

2

Try this:

- (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];

}

It goes through each title and prepends a dollar sign into a new string, and adds it to a new array, which is returned.

Jonathan.
  • 53,997
  • 54
  • 186
  • 290