Wenn ich meine HealthKit-Daten mit HKSampleQuery abrufe, erstelle ich ein Array und befülle dann eine Tabellenansicht. Wenn ich dies tue, hat meine TableViewCell jedoch viele andere Zeichen nach der Blutzuckernummer. Hier ist ein Screenshot der Zelle:Zusätzliche Zeichen beim Ziehen von HealthKit
Heres, wo ich die Daten abfragen. Jede Hilfe bitte!
let endDate = NSDate()
let startDate = NSCalendar.current.date(byAdding: .day, value: number, to: endDate as Date)
let sampleType = HKSampleType.quantityType(forIdentifier: HKQuantityTypeIdentifier.bloodGlucose)
let mostRecentPredicate = HKQuery.predicateForSamples(withStart: startDate, end: endDate as Date, options: [])
let query = HKSampleQuery(sampleType: sampleType!, predicate: mostRecentPredicate, limit: HKObjectQueryNoLimit, sortDescriptors: nil) { (query, results, error) in
if let results = results as? [HKQuantitySample] {
self.bloodGlucose = results
}
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
healthStore.execute(query)
Hier ist, wo ich Setup die Tableview ...
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return bloodGlucose.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let currentCell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
let sugar = bloodGlucose[indexPath.row]
currentCell.textLabel?.text = "\(sugar)"
currentCell.detailTextLabel?.text = dateFormatter.string(from: sugar.startDate)
return currentCell
}
Bitte fügen Sie den Code ein, den Sie zum Einrichten der Tabellenansichtszellen verwenden. – Allan
Ich habe die Frage bearbeitet, um dies zu berücksichtigen. @Allan – Johnd