내 coredata 관계 가져 오기 요청이 NSSet 객체를 반환합니다. 정렬되지 않은 NSset 이후에 어떻게 tableview 데이터 소스에 대해이 데이터를 설정할 수 있습니까? NSSet을 NSArray로 변환 할 수 있지만 같은 순서로 데이터를 반환합니다.어떻게 UItableView 데이터 소스 CoreData 관계에서 설정합니까.
0
A
답변
0
Apple is clear "배열에있는 개체의 순서는 정의되지 않았습니다." 그래서 나는 그것을 바꿀 수 있다고 기대할 것입니다.
allObjects
배열을 인스턴스 변수에 저장하고이를 사용하여 numberOfSectionsInTableView()
및 다른 데이터 소스 메서드를 구현하는 것이 좋습니다.
당신은 또한 같은 인스턴스 변수에 NSFetchedResultsController
을 저장하고 안전하게 사용할 수 있습니다
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var rows = 0
if self.fetchedResultsController!.sections!.count > 0 {
let sectionInfo = getSectionInfo(section)
rows = sectionInfo!.numberOfObjects
}
return rows
}
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
let sectionInfo = getSectionInfo(section)
return sectionInfo!.name
}
func getSectionInfo(section: Int) -> NSFetchedResultsSectionInfo? {
var sections: [AnyObject] = self.fetchedResultsController!.sections!
if section < sections.count {
let x = sections[section] as! NSFetchedResultsSectionInfo
return x
}
return nil
}
override func tableView(tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int {
return self.fetchedResultsController!.sectionForSectionIndexTitle(title, atIndex: index)
}
override func sectionIndexTitlesForTableView(tableView: UITableView) -> [String]? {
return self.fetchedResultsController!.sectionIndexTitles
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("YourCellIdentifier")! as UITableViewCell
// Use your own NSManagedObject class here...mine is Category
let category = self.fetchedResultsController.objectAtIndexPath(indexPath) as! Category
return cell
}
난 난 그냥 cellForRowAtIndexPath()
을 구현할 수 있도록 재사용 기본 클래스 위의 모든 방법을 코딩 한 각각의 새로운 테이블보기에서. 다른 사람에게 유용 할 수도 있으므로 a copy on github이라고 게시했습니다.
관련 문제
- 1. 관계에서 CoreData 가져 오기
- 2. iPhone - UITableView 데이터 소스?
- 3. UITableView 및 데이터 소스
- 4. 섹션이있는 UITableView CoreData 주문
- 5. CoreData + UITableView, Messages.app replica
- 6. 행 추가 uitableview-coreData
- 7. UITableView 데이터 소스 업데이트 문제
- 8. UITableView + 대형 웹 데이터 소스
- 9. CoreData - 하나의 관계에서 특정 관계를 선택
- 10. UITableView + 코어 데이터
- 11. 데이터 테이블에서 세로를 어떻게 설정합니까?
- 12. 일관된 업데이트 Coredata 업데이트 후 UITableview
- 13. UITableView 및 CoreData - 특정 행 및 효율성의 데이터 표시?
- 14. 관계에서 데이터 추출
- 15. 관계에서 데이터 처리하기
- 16. 내가이 코어 데이터 모델을 가지고, Coredata
- 17. UITableview 데이터 소스 메서드 및 데이터 소스로 json을 검색하십시오.
- 18. MVVMCross - UITableView 소스 업데이트
- 19. CoreData 테스트 데이터?
- 20. CoreData 데이터 되돌리기
- 21. JSON 데이터 UITableView to UITableView
- 22. 소스 외부에서 UITableViewCell의 내용을 설정합니까?
- 23. UITableView 데이터 소스 문제입니다. UITableView : cellForRowAtIndexPath :가 호출 될 때 갑자기 데이터 배열이 비어졌습니다.
- 24. 너무 많은 관계에서 두 속성을 비교하는 CoreData 술어
- 25. 주문한 다 대다 CoreData 관계에서 객체를 제거/대체하려면 어떻게합니까?
- 26. UITableView에서 데이터 소스 및 델리게이트는 어떻게 작동합니까?
- 27. 원격 데이터 소스로 UITableView 초기화하기
- 28. CopyFile은 소스 파일에 잠금을 설정합니까?
- 29. Obj-C : UITableView 업데이트 데이터 소스 크로스 클래스
- 30. 어떻게 UITableView 인덱싱?
도움 주셔서 감사합니다. 하지만 한 가지 의심의 여지가 allobjects() 메서드는 NSSet을 추가 한 것과 같은 순서로 배열을 반환합니다. –
첫 단락을 추가했습니다. 'allObjects()'순서는 정의되어 있지 않으므로 변경 될 수 있습니다. – user212514