gpt4 book ai didi

ios - UITableView在每个节的单元格中重复相同的字符串

转载 作者:行者123 更新时间:2023-12-01 18:11:10 25 4
gpt4 key购买 nike

我有一个字符串数组,希望UITableView中的每个部分都将相应的字符串用作其行的标题。而不是这样做,它只是获取数组中的第一个字符串并在每个节中重复它。

我似乎无法弄清楚我的设置有什么问题。我记录了indexPath.sectionagendaTableArray值,并且在我滚动浏览表格时可以正确记录,但是它仍然仅显示第一个值。

阵列设置:

- (void)viewDidLoad
{
[super viewDidLoad];

/// code clipped for brevity

self.agendaTableArray = [[NSArray alloc] init];

self.agendaTableArray = @[@"No events today!", @"No events today!", @"Dinner with Rebekah", @"Soccer game", @"Dentist appt.", @"Celebrate job offer, drinks with Pierre!", @"No events today!", @"No events today!", @"No events today!", @"No events today!", @"No events today!", @"No events today!", @"No events today!", @"No events today!", @"No events today!", @"No events today!", @"No events today!"];

}

表设置:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyReuseIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier];
}

NSLog(@"the indexpath.section is: %ld", (long)indexPath.section);
NSLog(@"the agendaTableArray title is: %@", self.agendaTableArray[indexPath.section]);


cell.textLabel.text = self.agendaTableArray[indexPath.row];
cell.textLabel.font = [UIFont systemFontOfSize:14];

[self whatSectionsAreVisible];

return cell;
}

最佳答案

您应该考虑检查每个部分有多少行。用顺序的话来说,您可能会为- (NSInteger)numberOfRowsInSection'返回值1,因此,您始终使用第一行的索引,即0。

您可能要使用:

cell.textLabel.text = self.agendaTableArray[indexPath.section];

关于ios - UITableView在每个节的单元格中重复相同的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31080711/

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