【发布时间】:2014-02-05 12:21:50
【问题描述】:
我有一个简单的 UITableView 从给定的 NSArray(NSDictionaries)以相反的顺序形成,以便新添加的单元格出现在顶部:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = [(NSDictionary*)list[list.count - indexPath.row - 1] objectForKey:@"name"];
return cell;
}
然后可以由用户手动对表格进行排序:
http://i.stack.imgur.com/kn8BV.png
我的问题是如何对数组进行排序,以便在用户下次启动应用程序时保持表格的新顺序。
【问题讨论】:
-
您可以尝试在字典中添加索引,这将保留所有添加项目的索引值。现在您可以根据索引排列数组了。
-
看看像
canMoveCellAtIndexPath这样的tableview代表 -
@Ashu,应该作为答案添加(关于在移动过程中维护字典的更多细节)
标签: ios uitableview sorting nsarray