按字母顺序从RSS排序iPhone TableView

时间:2012-09-20 16:20:44

标签: iphone xml uitableview rss

我正在尝试将我的播客视图从pubDate排序更改为按字母顺序排序。用于解析当前日期的RSS的代码是:

 NSMutableArray *entries = [NSMutableArray array];
        [self parseFeed:doc.rootElement entries:entries];

        [[NSOperationQueue mainQueue] addOperationWithBlock:^{

            for (RSSEntryDirectory *entry in entries) {

                int insertIdx = [_allEntries indexForInsertingObject:entry sortedUsingBlock:^(id a, id b) {
                    RSSEntryDirectory *entry1 = (RSSEntry *) a;
                    RSSEntryDirectory *entry2 = (RSSEntry *) b;
                    return [entry1.articleDate compare:entry2.articleDate];
                }];

                [_allEntries insertObject:entry atIndex:insertIdx];
                [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:insertIdx inSection:0]]
                                      withRowAnimation:UITableViewRowAnimationRight];

            }

        }];

如何通过其他条目属性之一将其更改为按字母顺序排列?

1 个答案:

答案 0 :(得分:0)

我认为你可以替换比较线:

return [entry1.articleDate compare:entry2.articleDate];

通过类似的东西(假设它是NSString对象):

return [entry1.articleTitle localizedCaseInsensitiveCompare:entry2.articleTitle];