gpt4 book ai didi

iphone - 表格 View 中的节数/行节数

转载 作者:行者123 更新时间:2023-11-28 22:58:50 24 4
gpt4 key购买 nike

我无法返回 numberofSections/numberofRows。我有一本充满数据的字典

-(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);}

它用这个 NSLogs

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";
}
);

对于 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;方法我如何检索索引的部分数;

对于 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;方法,如何检索该部分中的行数?

编辑

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSArray *array = [letterArray mutableCopy];
return [[array objectAtIndex:section]count];}

它给了我这个错误:-[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0x8434cc0

提前致谢

最佳答案

对于 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 你应该这样做:

return [letterArray count];

对于 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 你应该这样做:

NSArray *array = letterArray;
return [[array objectAtIndex:section] count];

编辑试试这个:

-(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;
}

你应该调用它一次并将它保存到一个类变量中,然后像这样为部分调用它:

[countArray count];

对于像这样的部分中的行:

[[countArray objectAtIndex:section] intValue];

关于iphone - 表格 View 中的节数/行节数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10332507/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com