你說你失去了鑰匙的順序,所以我想你從NSArray
拉那些鑰匙。對?並在那NSArray
你有你想要的鍵排序。而且我也看到NSDictionary
的對象是Arrays
,對吧?是。所以在你的Ordered Array
你有更多的數組。
data
是NSDictionary的名稱。
所以,你所要做的就是將NSArray
(按你想要的順序排列)放到這個.m文件中,然後在你的cellForRowAtIndexPath
方法中使用一些很棒的代碼。您可以通過執行以下操作步驟:
@interface yourViewController()
{
NSArray *yourArrayOrdered;
}
@end
@implementation yourViewController
- (void)viewDidLoad
{
[super viewDidLoad];
yourArrayOrdered = [[NSArray alloc] initWith...:... ];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *key = yourArrayOrdered[indexPath.row];
NSArray *list = [self.data objectForKey:yourArrayOrdered[indexPath.row]];
//your code continues here...
/*id data = list[indexPath.row]; //don't think you need this line
PSSearchCell *cell = [PSSearchCell newCellOrReuse:tableView];
cell.model = data; */
return cell;
}
這是所有你必須做的,讓使用的NSDictionary的NSArray和你想要的順序。
爲了更好地觀察它,在你的有序陣列只包含字符串它會是這樣的情況:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *key = yourArrayOrdered[indexPath.row];
NSString *myString = [self.data objectForKey:yourArrayOrdered[indexPath.row]];
cell.textLabel.text = [NSString stringWithFormat:@"THIS IS THE OBJECT %@", myString];
cell.detailTextLabel.text = [NSString stringWithFormat:@"AND THIS IS THE KEY %@", key];
return cell;
}
希望它能幫助。
這些鑰匙永遠不會在訂購地點。字典沒有訂單。 –
可能重複的[我如何得到原始順序的NSDictionary/NSMutableDictionary?](http://stackoverflow.com/questions/3386921/how-can-i-get-original-order-of-nsdictionary-nsmutabledictionary) – Amar