當我使用HKSampleQuery抽取我的HealthKit數據時,我創建了一個數組,然後填充tableview。但是,當我這樣做時,我的tableViewCell在血糖數量後還有許多其他字符。下面是該小區的截圖:從HealthKit中提取額外字符
繼承人在那裏我查詢數據。請任何幫助!
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)
這裏就是我的設置...的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
}
請包括您用於設置表格視圖單元格的代碼。 – Allan
我編輯了這個問題。 @Allan – Johnd