• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

[复制链接]
菜鸟教程小白 发表于 2022-12-12 10:03:02 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

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

以下是相关代码:

- (void)tableViewUITableView *)tableView didDeselectRowAtIndexPathNSIndexPath *)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)changeFontToNSString *)fontFamily {
    self.textToReadLabel.font = [UIFont fontWithName:fontFamily size:self.textToReadLabel.font.pointSize];
}

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

- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)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;
}

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



Best Answer-推荐答案


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

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

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap