gpt4 book ai didi

ios - 将 NSMutableArray 的 NSMutableDictionary 的 key Value 放在 UITableViewCell 上

转载 作者:行者123 更新时间:2023-11-29 03:59:41 25 4
gpt4 key购买 nike

我是 iPhone 开发新手。

我有数组字典。

{
A = (
{
address = "Talala (gir)";
"main_id" = 1;
mobile = 8878876884;
name = "Amit Patel";
},
{
address = "Junagdh";
"main_id" = 5;
mobile = 4894679865;
name = "Arjun Patel";
}
);
J = (
{
address = "Taveli";
"main_id" = 6;
mobile = 87886356085878;
name = "Jasmin Patel";
},
{
address = "Gujarat";
"main_id" = 4;
mobile = 6636633368;
name = "Jatin ";
}
);
R = (
{
address = "Mumbai";
"main_id" = 2;
mobile = 999686322;
name = "Rajan Patel";
}
);
S = (
{
address = "Rajkot";
"main_id" = 3;
mobile = 8866086549;
name = "Sumit Patel";
}
);
}

我有UITableView,我想在UITableViewCell上显示具有“name”键的值

我的cellForRowAtIndexPath方法是

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

cell.textLabel.text = [[[self.finalPDic objectForKey:[self.listOfHeader objectAtIndex:indexPath.row]] objectAtIndex:indexPath.row] objectForKey:@"name"];
return cell;
}

但是上面的代码对我来说不起作用。

最佳答案

这段代码有很多问题......

第一个indexPath.row必须是indexPath.section

作为一般提示,最好将代码组织得更具可读性,例如:

NSArray* nameArrayForLetter = [self.finalPDic objectForKey:[self.listOfHeader objectAtIndex:indexPath.section];
NSDictionary* addressDict = [nameArrayForLetter objectAtIndex:indexPath.row];
NSString* nameString = [addressDict objectForKey:@"name"];

关于ios - 将 NSMutableArray 的 NSMutableDictionary 的 key Value 放在 UITableViewCell 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16053394/

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