【发布时间】:2017-12-05 19:28:04
【问题描述】:
我正在使用以下内容填充 UITableView 部分的部分:
fetchedResultsController =
NSFetchedResultsController(fetchRequest: fetchRequest,
managedObjectContext: managedContext,
sectionNameKeyPath: #keyPath(Players.team),
cacheName: nil)
我的 UITableView 在该部分中有team。我还想将城市添加到该部分。我不认为我可以在该部分中添加两个项目。我可以看到以下具有所需的数据。但是如何检索城市信息?
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
let sectionInfo = fetchedResultsController.sections?[section]
print("sectionInfo \(String(describing: sectionInfo?.objects))")
return sectionInfo?.name
}
结果:
sectionInfo Optional([<Time_on_Ice.Players: 0x1c028cf30> (entity: Players; id: 0xd000000000100000 <x-coredata://EE1C8D6B-3FC5-4460-9F7F-3830328B6688/Players/p4> ; data: {
birthdate = "1990-02-07 05:00:00 +0000";
city = "Tampa Bay";
division = Atlantic;
firstName = Steven;
headshot = <ffd8ffe0 00104a46 49460001 01000048 00480000 ffe10058 45786966 00004d4d 002a0000 00080002 01120003 00000001 0001>;
height = "5'11\"";
lastName = Stamkos;
league = NHL;
level = Professional;
number = 91;
playersShiftRelationship = "<relationship fault: 0x1c403d060 'playersShiftRelationship'>";
position = Centre;
shoots = Right;
team = Lightning;
weight = "177 lb";
})])
【问题讨论】:
标签: swift core-data nsfetchedresultscontroller sections