2012-09-20 313 views
0

我想改變我的播客視圖從排序通過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

回答

0

我想你可以替換比較線:

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

通過類似的東西(假設它是NSString對象):

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