i need display in uitableview content of nsdictionary returned api, respecting order of keys.
i'm using :
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { nsstring *key = self.data.allkeys[indexpath.section]; nsarray *list = self.data[key]; id data = list[indexpath.row]; pssearchcell *cell = [pssearchcell newcellorreuse:tableview]; cell.model = data; return cell; } but self.data.allkeys, i'm loosing order of keys. can't sort them value doesn't concern them.
try this,
nsarray *keys = [mydictionary allkeys]; keys = [keys sortedarrayusingcomparator:^(id a, id b) { return [a compare:b options:nsnumericsearch]; }]; nslog(@"%@",keys); now fetch values based on key sorted.
edit
to sort them in alphabetical order try this,
nsarray *keys = [mydictionary allkeys]; keys = [[keys mutablecopy] sortusingselector:@selector(localizedcaseinsensitivecompare:)]; nslog(@"%@",keys);
Comments
Post a Comment