Step 2: Describe your environment
- Objective C or Swift: Swift
- iOS version: 8.4
- Firebase SDK version: 3.7.0, Core 3.4.3, Database 3.0.3
- FirebaseUI version: 0.5.5
- CocoaPods Version: 1.0.1
Step 3: Describe the problem:
I need to sort tableview according user default preferences like favorite
So the data favorite not save on my real database
How can I sort the datasource ? maybe from populateCellWithBlock (I use it to bod the favorite item) ?
Observed Results:
Expected Results:
Relevant Code:
override func viewDidLoad() {
super.viewDidLoad()
// Firebase database
self.ref = FIRDatabase.database().reference()
self.dataSource = FirebaseTableViewDataSource(query: self.ref.child("libraries"),
prototypeReuseIdentifier: self.libraryCellIdentifier,
view: self.mTableView)
// I understand that override numberOfRowsInSection and cellForRowAtIndexPath
self.dataSource!.populateCellWithBlock { (cell: UITableViewCell, obj: NSObject) -> Void in
let libraryCell = cell as! LibraryCell
let snap = obj as! FIRDataSnapshot
let library = Library(snapshot: snap)
libraryCell.mLibraryNameLabel.text = library.name
// changed font works
if self.librariesFavorite.contains(String(library.id)) {
library.favorite = true
libraryCell.mLibraryNameLabel.font = UIFont.boldSystemFontOfSize(15.0)
} else {
library.favorite = false
libraryCell.mLibraryNameLabel.font = UIFont.systemFontOfSize(15.0)
}
self.libraries.append(library)
}
self.mTableView.dataSource = dataSource
self.mTableView.delegate = self
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
// refresh with new favorite data when your come from detail library
self.librariesFavorite = Helpers.getFavorite("Libraries")
// sort by favorite before load
// self.libraries.sortInPlace({$0.favorite && !$1.favorite})
self.mTableView.reloadData()
}
Step 2: Describe your environment
Step 3: Describe the problem:
I need to sort tableview according user default preferences like favorite
So the data favorite not save on my real database
How can I sort the datasource ? maybe from populateCellWithBlock (I use it to bod the favorite item) ?
Observed Results:
Expected Results:
Relevant Code: