按字母顺序排序iPhone TableView从RSS按字母顺序排序

问题描述:

我想改变我的播客视图从排序通过pubDate排序。在目前解析RSS的日期使用的代码是:按字母顺序排序iPhone TableView从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

你就不能修改行'[取值范。 articleDate比较:entry2.articleDate];'比较其他属性? –

+0

甚至可以使用任何'sort'脚本进行排序,同时显示在'tableView'中。 – vishy

我想你可以替换比较线:

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

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

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