あなたはキーの順序を失っていると言ったので、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;
}
それが役に立てば幸い。