iphone - 如何反转 NSMutableArray 中的数据?

标签 iphone objective-c xcode ios4 nsmutablearray

<分区>

Possible Duplicate:
How to display an array in reverse order in objective C

我有一个 NSMutableArray,这个数组很好地包含了 UITableView 中的信息。 但我想首先在 UITableView 中显示最新信息。现在,最早的信息首先出现在 UITableView 中。我的代码如下:

NSMutableArray *entries = [NSMutableArray array];
[self parseFeed:doc.rootElement entries:entries];
for (RSSEntry *entry in entries) {
    [allEntries insertObject:entry atIndex:0];   //insertIdx];
    [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationRight];
}

那我怎样才能反转NSMutableArray中的信息呢?

最佳答案

以相反的顺序枚举条目的内容如何?

for (RSSEntry *entry in [entries reverseObjectEnumerator]) {
    ...
}

如果你只想获取一个数组并创建一个反向数组,你可以这样做:

NSArray *reversedEntries = [[entries reverseObjectEnumerator] allObjects];

关于iphone - 如何反转 NSMutableArray 中的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8276377/

相关文章:

ios - 使用 arc4random() 在两个整数之间生成随机数

iOS 应用程序在模拟器中运行,启动时发生临时分发崩溃

c - 这个简单的 C 程序有什么问题?

ios - 在WebView中打开所有白名单URL

iphone - iOS didSelectTabBarItem 知道之前选择了什么项目

iphone - 解雇ModalViewController与过渡: left to right

ios - iOS 中 echoprint 的链接器错误

ios - fatal error : unexpectedly found nil while unwrapping an Optional value in Tableview

objective-c - "Source List"中仅某些项目的上下文菜单

ios - 如何在iOS 10中顺利翻译iMessage扩展中的 View ?