TableViewをセットアップしようとしていますが、問題が発生しています。NSArrayの値は互いに異なります。わかりにくいことは承知しておりますが、一生懸命説明させていただきます。例えば
-(void)setUpContacts{
//set up the contacts
NSString *string = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
letterArray = [[NSMutableDictionary alloc]init];
Contacts *contact = [[Contacts alloc]init];
contactNumbers = [contact phoneNumbers];
for (NSDictionary* info in contactNumbers) {
firstLetter = [info objectForKey:@"lastName"];
index = @"_";
if([firstLetter length] > 0){
firstLetter =[firstLetter substringToIndex:1];
firstLetter= [firstLetter capitalizedString];
NSRange range = [string rangeOfString:firstLetter];
if(range.length >= 0){
index= firstLetter;
}
}
if(![letterArray objectForKey:index]){
[letterArray setValue:[NSMutableArray array] forKey:index];
}
[[letterArray objectForKey:index] addObject:info];
}NSLog(@"%@",letterArray);}
-(NSArray *)getLetterArraycount{
NSMutableArray *countArray = [[NSMutableArray alloc]init];
NSNumber *subCount;
for(id key_main in letterArray){
subCount = 0;
for(id key_sub in [letterArray objectForKey:key_main]){
subCount = [NSNumber numberWithInt:[subCount intValue]+1];
}
[countArray addObject:subCount];
}
return countArray;
}
- (void)viewDidLoad{
[super viewDidLoad];
[self setUpContacts];
countArrays = [self getLetterArraycount];
indexPaths = [[NSMutableDictionary alloc]init];
NSArray *temp = [letterArray allKeys];
NSLog(@"%@",temp);
NSLog(@"%@",countArrays);
//set up the tableView
self.myTableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
self.myTableView.delegate = self;
self.myTableView.dataSource = self;
self.title = @"Select Friends";
self.myTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:myTableView];}
コンソールにこのようにログを記録します
C = (
{
firstName = Alex;
kind = Mobile;
lastName = Chang;
name = "Alex Chang (Mobile)";
number = "(555) 555-5555";
},
{
firstName = YuYu;
kind = Mobile;
lastName = Chen;
name = "YuYu Chen (Mobile)";
number = "(408) 112-2334";
},
{
firstName = Chris;
kind = Mobile;
lastName = Choi;
name = "Chris Choi (Mobile)";
number = "(999) 999-9999";
},
{
firstName = Kevin;
kind = Mobile;
lastName = Chung;
name = "Kevin Chung (Mobile)";
number = "1 (231) 241-2312";
}
);
H = (
{
firstName = Danny;
kind = Mobile;
lastName = Huang;
name = "Danny Huang (Mobile)";
number = "(408) 599-9770";
},
{
firstName = Ice;
kind = Mobile;
lastName = Huang;
name = "Ice Huang (Mobile)";
number = "(408) 444-4444";
}
);
K = (
{
firstName = Will;
kind = Mobile;
lastName = King;
name = "Will King (Mobile)";
number = "(415) 123-4567";
}
);
L = (
{
firstName = "";
kind = iPhone;
lastName = LastName;
name = " LastName (iPhone)";
number = "(408) 123-2555";
},
{
firstName = david;
kind = Mobile;
lastName = lub;
name = "david lub (Mobile)";
number = "(666) 666-1111";
}
);
P = (
{
firstName = Jennifer;
kind = Mobile;
lastName = Pie;
name = "Jennifer Pie (Mobile)";
number = "(666) 666-6666";
}
);
S = (
{
firstName = Martin;
kind = Mobile;
lastName = Shen;
name = "Martin Shen (Mobile)";
number = "(415) 333-1234";
},
{
firstName = Francis;
kind = Mobile;
lastName = Shung;
name = "Francis Shung (Mobile)";
number = "(408) 345-6789";
}
);
V = (
{
firstName = Brian;
kind = Mobile;
lastName = Vu;
name = "Brian Vu (Mobile)";
number = "(408) 234-5678";
}
);
Y = (
{
firstName = Qiu;
kind = Mobile;
lastName = Yang;
name = "Qiu Yang (Mobile)";
number = "(408) 567-8901";
}
);
Z = (
{
firstName = Joy;
kind = Mobile;
lastName = Zhou;
name = "Joy Zhou (Mobile)";
number = "(408) 765-4321";
}
);
"_" = (
{
firstName = FirstName;
kind = Mobile;
lastName = "";
name = "FirstName (Mobile)";
number = "1 (408) 234-5141";
}
);
}
2012-04-26 16:14:05.195 UpOut[2693:15803] (
L,
Y,
V,
"_",
Z,
S,
K,
C,
P,
H
私の質問は、なぜ最初に「C」をログに記録しないのに、代わりに「L」をログに記録するのかということです。