gpt4 book ai didi

ios - 在我的 UITableView 中选择一个单元格时,选择似乎是随机的

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:43:56 25 4
gpt4 key购买 nike

我有一个以编程方式创建的 UITableView 以及单元格,它显示了一个字体列表,用户可以从中选择以更改他们阅读时使用的字体。然而,在表格 View 中点击一个单元格时,与委托(delegate)一起发送回的字体系列不是单元格中显示的字体。前一分钟点击“Times New Roman”会将其更改为 Helvetica,下一分钟就会将其更改为 Baskerville。

相关代码如下:

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
// Depending on which row (font) they selected, use the delegate to change the
// reading text to that font
switch (indexPath.row) {
case 0:
[self.delegate changeFontTo:@"Helvetica"];
break;
case 1:
[self.delegate changeFontTo:@"Times New Roman"];
break;
case 2:
[self.delegate changeFontTo:@"Baskerville"];
break;
case 3:
[self.delegate changeFontTo:@"OpenDyslexic"];
break;
}
}

委托(delegate)方法:

- (void)changeFontTo:(NSString *)fontFamily {
self.textToReadLabel.font = [UIFont fontWithName:fontFamily size:self.textToReadLabel.font.pointSize];
}

如果有帮助,这里是用于创建行的 UITableView 委托(delegate)方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"FontCell";

FontCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

int row = indexPath.row;

cell.selectionStyle = UITableViewCellSelectionStyleBlue;
cell.fontFamilyLabel.text = self.fonts[row];

if ([self.fonts[row] isEqualToString:@"Helvetica"]) {
cell.fontFamilyLabel.font = [UIFont fontWithName:@"Helvetica" size:17.0];
}
else if ([self.fonts[row] isEqualToString:@"Times New Roman"]) {
cell.fontFamilyLabel.font = [UIFont fontWithName:@"Times New Roman" size:17.0];
}
else if ([self.fonts[row] isEqualToString:@"Baskerville"]) {
cell.fontFamilyLabel.font = [UIFont fontWithName:@"Baskerville" size:17.0];
}
else if ([self.fonts[row] isEqualToString:@"Dyslexic"]) {
cell.fontFamilyLabel.font = [UIFont fontWithName:@"OpenDyslexic" size:17.0];
}

return cell;
}

真的很困惑它可能是什么。我对代码一头雾水,但我觉得这可能只是一个我不理解的概念导致了问题。

最佳答案

您在委托(delegate)中使用了 didDeselectRowAtIndexPath 而不是 didSelectRowAtIndexPath

关于ios - 在我的 UITableView 中选择一个单元格时,选择似乎是随机的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15788024/

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