0
我新的IOS,我真的停留在此找到解決辦法是...SortedArrayUsingSelector無法識別選擇
animals = @{@"B" : @[@"Bear", @"Black Swan", @"Buffalo"],
@"C" : @[@"Camel", @"Cockatoo"],
@"D" : @[@"Dog", @"Donkey"],
@"E" : @[@"Emu"],
@"G" : @[@"Giraffe", @"Greater Rhea"],
@"H" : @[@"Hippopotamus", @"Horse"],
@"K" : @[@"Koala"],
@"L" : @[@"Lion", @"Llama"],
@"M" : @[@"Manatus", @"Meerkat"],
@"P" : @[@"Panda", @"Peacock", @"Pig", @"Platypus", @"Polar Bear"],
@"R" : @[@"Rhinoceros"],
@"S" : @[@"Seagull"],
@"T" : @[@"Tasmania Devil"],
@"W" : @[@"Whale", @"Whale Shark", @"Wombat"]};
animalSectionTitles = [[animals allKeys] sortedArrayUsingSelector:@selector(compare:)];
上面的代碼沒有錯誤,但是當我試圖插入數組NSDictionary中,它總是顯示無法識別的選擇。我該怎麼做才能解決這個問題?
while (sqlite3_step(statement)==SQLITE_ROW) {
Word *univer = [[Word alloc] init];
univer.Id =[NSString stringWithUTF8String:(char *) sqlite3_column_text(statement,0)];
univer.word=[NSString stringWithUTF8String:(char *) sqlite3_column_text(statement,1)];
//NSLog(@"%@",univer.word);
NSString *first = [univer.word substringToIndex:1];
NSLog(@"%@",first);
if([first isEqualToString:@"A"] || [first isEqualToString:@"a"]){
[_A addObject:univer.word];
}
else if([first isEqualToString:@"B"] || [first isEqualToString:@"b"]){
[_B addObject:univer.word];
}
else if([first isEqualToString:@"C"] || [first isEqualToString:@"c"]){
[_C addObject:univer.word];
}
else if([first isEqualToString:@"D"] || [first isEqualToString:@"d"]){
[_D addObject:univer.word];
}
else if([first isEqualToString:@"E"] || [first isEqualToString:@"e"]){
[_E addObject:univer.word];
}
else if([first isEqualToString:@"F"] || [first isEqualToString:@"f"]){
[_F addObject:univer.word];
}
else if([first isEqualToString:@"G"] || [first isEqualToString:@"g"]){
[_G addObject:univer.word];
}
else if([first isEqualToString:@"H"] || [first isEqualToString:@"h"]){
[_H addObject:univer.word];
}
}
animals= [NSDictionary dictionaryWithObjectsAndKeys:_A,_B,_C,_D,_E,_F,_G,_H, nil];
animalSectionTitles = [[animals allKeys] sortedArrayUsingSelector:@selector(compare:)];
感謝一個很好的解釋......它的工作原理。 – user3020676 2014-11-23 22:48:03
好奇爲什麼答案被標記爲接受,然後沒有標記(注意,我沒有downvote你的問題)。答案有問題嗎? – ospr 2014-11-25 00:39:03
我很抱歉,這可能是因爲我的網絡問題...很抱歉... – user3020676 2014-12-03 09:48:09