我的數據模型定製獲取核心數據(SWIFT)
取FUNC
func fetchAndSetResults2(){
let dataController = DataController.sharedController
let moc = dataController.managedObjectContext
let request = NSFetchRequest(entityName: "Cart")
let formatSort = NSSortDescriptor(key: "cartId", ascending: true)
request.sortDescriptors = [formatSort] //[formatSort, nameSort]
request.predicate = NSPredicate(format: "cartToUser.userId = %@", serverUserId)
fetchedResultController = NSFetchedResultsController(fetchRequest: request, managedObjectContext: moc, sectionNameKeyPath: "cartId", cacheName: nil)
fetchedResultController.delegate = self
do {
try fetchedResultController.performFetch()
}
catch {
fatalError("Error in fetching records")
}
}
更新:排
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
if let sections = fetchedResultController.sections {
return sections.count
}
return 0
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if let sections = fetchedResultController.sections {
let currentSection = sections[section]
return currentSection.numberOfObjects
}
return 0
}
的數量我在覈心數據新。我已經從購物車實體獲取數據。我的表格視圖看起來像截圖。看看Cart-user(38)-363690,它顯示1個購物車Id中的2個單元格,因爲它有2張照片。如何只顯示一個單元,即使它有兩張或更多照片?
問題可能與數量的切片和numberofrowsinsection方法。請在這裏添加方法 – Johnykutty
好吧,請檢查我編輯的問題@Johnykutty –
購物車用戶(38)-XXXXX是表格視圖單元格或其部分標題的一部分? – Johnykutty