gpt4 book ai didi

iphone - 如何正确地将 NSDictionary 值传递给 UITableViewCell

转载 作者:行者123 更新时间:2023-11-29 04:58:17 25 4
gpt4 key购买 nike

嘿,大家好,我有一个问题,我有一个 NSArrays 的 NSDictionary,我试图设置字母顺序部分,例如 AAAAA、BBBB、CCCC...等,但是当我将我的值传递给它打印出所有 A 值时直接进入一个 uitableviewcell,然后 B 进入下一个...这不是我所追求的。我希望每个 UItableviewcell 都有一个按字母顺序排列的部分,其中包含一个 NSArray/Dictionary 值..

这就是我目前的设置方式,我想也许我可能缺少一个 If 语句,但是我只是不确定如何执行此操作,所以如果可能的话希望获得一些帮助..提前致谢。

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

cell.accessoryType = UITableViewCellAccessoryNone; //make sure their are no tickes in the tableview
cell.selectionStyle = UITableViewCellSelectionStyleNone; // no blue selection

// Configure the cell...
if(indexPath.row < [self.arraysByLetter count]){

NSArray *keys = [self.arraysByLetter objectForKey:[self.sectionLetters objectAtIndex:indexPath.row]];
NSString *key = [keys description];
NSLog(@"thingy %@", key);

cell.textLabel.text = key;
}

return cell;
}

这就是模拟器上的样子 enter image description here

更新我按照下面的建议对我的代码进行了更改,现在这就是发生的事情......

当模拟器第一次加载时 enter image description here

然后我滚动到列表底部并返回到顶部,它看起来像这样。 enter image description here

最佳答案

NSString *key = [keys description];

在这里,您将文本设置为ALL键的字符串表示形式。 :)

我认为你想要这个(并且我希望我已经正确解释了你的代码)

NSArray *keys = [self.arraysByLetter objectForKey:[self.sectionLetters objectAtIndex:indexPath.section]];
NSString *key = [keys objectAtIndex:indexPath.row];
NSLog(@"thingy %@", key);

因此,使用 IndexPath 部分获取 KeysArray,然后使用 IndexPath 行获取单元格的值。

关于iphone - 如何正确地将 NSDictionary 值传递给 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7523827/

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