- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
在我的带有 tableView 的 viewController 中,我有使用 fetchedResultsController 从核心数据数据库中获取的对象列表。我按部分对所有获取的结果进行了分组。它工作正常,我已经实现了以下方法来启用出现在 TableView 右侧的 A-Z sectionIndexes:
func sectionIndexTitles(for tableView: UITableView) -> [String]? {
let indexTitles = self.fetchedResultsController.sectionIndexTitles
return indexTitles
}
func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int {
return self.fetchedResultsController.section(forSectionIndexTitle: title, at: index)
}
我还有这个 fetchedResultsController
的声明
var fetchedResultsController: NSFetchedResultsController<Object>!
self.fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: context!, sectionNameKeyPath: "project.group.name", cacheName: nil)
sectionIndexTitles 在我的 Core Data 数据库中有英文的 group.name 值时工作正常,但是当我有另一种语言的 group.name 值(或英文与非英文混合)时 sectionIndexTitles
是向我显示(返回)英文字母,但对于非英文字母,它会返回问号或英文字母。
例如它返回这样的数组 ["A", "B", "F", "G", "R", "S", "A", "E"]
,而不是像这样返回数组 ["A", "B", "F", "G", "R", "S", "Letter in another language", "Letter in another language"]
。我更改了语言方案,它返回 ["A"、"B"、"F"、"G"、"R"、"S"、"?"、"?"]
。它将非英文字母替换为英文字母或显示“?”,而不是显示另一种语言的值。
不知道是不是bug?或者它可能无法显示不同语言的字母。问题出在哪里,如何解决?
我使用的是 Swift 3、Xcode 8.3.3。
最佳答案
我遇到了同样的问题,对于俄语,它返回了我!而不是字符。所以我执行了这个解决方案:
override func sectionIndexTitles(for tableView: UITableView) -> [String]? {
if let sections = fetchedResultsController?.sections {
var sectionTitles: [String] = []
for section in sections {
sectionTitles.append(String(describing: section.name.first!))
}
return sectionTitles
}
return fetchedResultsController?.sectionIndexTitles
}
我认为这可以用于大多数情况
关于swift - sectionIndexTitles(对于 tableView : UITableView) method returns strange results,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45551243/
这个问题在这里已经有了答案: How do I compare strings in Java? (23 个回答) 关闭 9 年前。 所以我运行了这段代码 String line =
此代码适用于我的网站: $(function(){ $('.link-follow-stop').on('click', function(event){ console.lo
private synchronized Map calculateStanding() { System.out.println("Calculate standing for
下面的程序 (prog1) 抛出 OutOfMemoryError 错误。确实如此。但如果我在第 5 行(prog2)下方添加 sysout,它不会抛出错误。这种奇怪的行为有什么原因吗? 程序1: p
class Foo(object): def __init__(self,x): self.x = x self.is_bar = False def
好的,我有一个设置了高度和宽度的简单 div。前后也设置了高度和宽度。它们都设置为显示为 block ,伪元素的内容为“”。 :before 在内容里面,而不是在它之前。:after 之前有一大堆奇怪
我无法解释 Scala 集合的这种行为。 让我们从一些定义开始。 import scala.collection.mutable.Set case class Item(name: String, c
在阅读我遇到的代码时,结构的以下定义和初始化: // header file struct foo{ char* name; int value; }; //Implementation file s
我正在尝试用 c 操作二进制数。我用下面的最小代码发现了一个奇怪的事情。谁能告诉我“+”和“|”有什么区别这里?谢谢! char next_byte1 = 0b11111111; char next_
我是德尔福的新手。在 TStrem 类的文档中,我读到它是一个抽象类。所以我认为当我尝试使用 创建它时编译器会出错 stream := TStream.Create(); 为什么不呢? 最佳答案 De
我有 2 个简单的表单,Form1 和 Form2 (Delphi 7)。 Form1 打开 Form2,我在那里等待特定的组合键 (Ctrl + F2)。一旦我关闭 Form2 并返回到 Form1
我有很多建立TCP网络的类-使用boost::asio,使用Packet进行传输。 (Packet的基类是std::vector) 我以为我已经解决了所有可能的内存泄漏,但是后来我在关闭客户端之前只是
我对以下声明有一些疑问: SELECT 1 FROM dual WHERE DECODE(1, 0, (SELECT COUNT(*) from tbl
我已经在 symfony 2.1 上安装了最新的 Sonata 管理包,但遇到了以下问题: 配置文件: services: app.geo.admin.city: class: App
我必须输出一系列先前保存在数据库中的随机图像。在输出的那一刻,而不是打印一张图片,代码打印一个奇怪的字符串(meaby dumpfile?): (¢Š(¢Š(¢Š(¢Š(¢Š(¢Š(¢Š(¢Š(¢Š(
我刚刚在从 Code Project 下载的项目中看到了这个: base.DialogResult = this.Result != null; 我不认为自己是 C# 新手,但这个对我来说是新手。谁能
看看这个...今天晚上我试图将一些 primiteves 转换到 wrapper 上时发现: Integer i = (Integer)4; Integer i = (Integer)4f; // D
我很少使用 Python,所以我不清楚为什么允许这样的行为:没有 w 对象,因此它没有 s 属性,那为什么 f 允许进行 w.s 赋值? >>> def f(): w.s="ads" #al
在 Jsfiddle 上:http://jsfiddle.net/jhzux/ 我在这个简单的脚本上浪费了很多时间。我想做的是在 jQuery 中启用克隆表单,然后使它们正常工作。 首先,当我在 Js
这是我的代码: .specific_tag_cases a:after{ position: absolute; font-family: Arial; background-
我是一名优秀的程序员,十分优秀!