gpt4 book ai didi

ios - 从字符串数组设置 UITable 中的详细文本标签

转载 作者:行者123 更新时间:2023-11-28 20:36:23 26 4
gpt4 key购买 nike

我正在使用主从应用程序模板。我硬编码了一个 NSArray 来设置文本标签:

groups = [[NSArray alloc] initWithObjects:@"Group1", @"Group2", nil];

然后我创建了两个数组,每个数组包含五个单词,并将这两个数组放入另一个数组中:

group1 = [[NSArray alloc] initWithObjects:@"A", @"and", @"find", @"go", @"have", nil];
group2 = [[NSArray alloc] initWithObjects:@"here", @"jump", @"not", @"on", @"one", nil];
groupWords = [[NSArray alloc] initWithObjects:group1, group2, nil];

在 tableView:cellForRowAtIndexPath 中:我试图将文本单元格设置为“Group#”,将详细文本设置为单词列表。我能够为每个单元格设置文本标签,但我似乎无法弄清楚如何传递字符串数组来设置每个详细信息文本标签。

例子:

第 1 组

A, and, find, go, have

第 2 组

这里,跳,不,上,一个

这是我目前所拥有的:

static NSString *CellIdentifier = @"Cell";

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

cell.textLabel.text = [groups objectAtIndex:[indexPath row]];

NSString *detailWords = [self.groupWords objectAtIndex:[indexPath row]];
NSLog(@"%@", detailWords);

cell.detailTextLabel.text =
return cell;

非常感谢任何帮助。

最佳答案

名为detailWords 的变量应该是一个数组而不是字符串。

然后按照您显示的方式在一行中格式化数组元素,您可以将它们连接成一个字符串,例如:

- (NSString *)stringFromArrayOfStrings:(NSArray *)array {
NSMutableString *result = [NSMutableString stringWithString:@""];
if ([array count] > 0) {
[result appendString:[array objectAtIndex:0]];
for (int i = 1; i < [array count]; i++) {
[result appendString:@", "];
[result appendString:[array objectAtIndex:i]];
}
}
return result;
}

关于ios - 从字符串数组设置 UITable 中的详细文本标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10376487/

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