Ios 对NSMutableDictionary中保存值的NSString进行排序
我正在uitextview中显示NSMutableDictionary值。但该值并不像我的代码那样按顺序保存:-Ios 对NSMutableDictionary中保存值的NSString进行排序,ios,Ios,我正在uitextview中显示NSMutableDictionary值。但该值并不像我的代码那样按顺序保存:- NSMutableArray *entries= [[NSMutableArray alloc] initWithObjects:@"Row 1", @"Row 2", @"Row 3", @"Row 4", @"Row 5",@"Row 6",@"Row 7",@"Row 8",@"Row 9", nil]; selectionStates = [[NSMutableDiction
NSMutableArray *entries= [[NSMutableArray alloc] initWithObjects:@"Row 1", @"Row 2", @"Row 3", @"Row 4", @"Row 5",@"Row 6",@"Row 7",@"Row 8",@"Row 9", nil];
selectionStates = [[NSMutableDictionary alloc] init];
-(void)done:(NSString *)aValue
{
[txtViewComponents resignFirstResponder];
NSString *compontentText = @"";
for(int i = 0; i< selectionStates.allKeys.count; i++)
{
int val = [[selectionStates objectForKey:[selectionStates.allKeys objectAtIndex:i]] intValue];
if(val == 1)
{
compontentText = [NSString stringWithFormat:@"%@ \n%@", compontentText,[selectionStates.allKeys objectAtIndex:i]];
}
}
if([compontentText hasPrefix:@" "])
compontentText = [compontentText substringFromIndex:2];
txtViewComponents.text = compontentText;
NSMUTABLEARRY*条目=[[NSMUTABLEARRY alloc]initWithObjects:@“第1行”、“第2行”、“第3行”、“第4行”、“第5行”、“第6行”、“第7行”、“第8行”、“第9行”、无];
selectionStates=[[NSMutableDictionary alloc]init];
-(void)done:(NSString*)aValue
{
[txtViewComponents辞职FirstResponder];
NSString*compontentText=@;
对于(int i=0;i
}
输出为:
第2排
第4排
第6行
第8行
一排
第3排
第5行
第7排
我想:
一排
第2排
第3排
第4排
第5行
第6行
第7排
第8行
如果有人有任何想法,请帮助我。您能显示
选择状态的结果吗
第2行第4行第6行第8行第1行第3行第5行第7行为什么您没有在数组的NSMutableDictionary
中尝试,原因是nsdictionary没有按相同的顺序重新运行值,在我的建议中,这里使用NSMutableArray
is条目是否在selectionStates中???像[selectionStates objectForKey:@“?”]什么是关键?我有NSMutableDictionary,虽然这个代码片段可以解决这个问题,但它确实有助于提高文章的质量。请记住,您将在将来回答读者的问题,这些人可能不知道您的代码建议的原因-
entries = [[NSMutableArray alloc]initWithArray:[entries sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]];