Nedense, verilerim tabloma görünmüyor. fetchTasks
işlevi çalışıyor gibi görünüyor, çünkü bana bir kesme noktası eklerseniz, tasks
içinde 151 Görevleri olduğunu ancak görevleri fetchTasks
işlevinin dışında herhangi bir yerden yazdırmaya çalıştığımda, bu görevlerin boş bir dizi olduğunu söyler . Bu nedenle, updateTableView
işlevimin çalışmamasının nedeni budur. Bu değişkenlerin her birini yazdırdığımda, bana boş bir dizi de verir. Xcode'ta hiç hata yapmıyorum, bu yüzden işe yaramayacak kadar sinir bozucu. Herhangi bir yardım harika olurdu. Zaten bir tonluk googling yaptım. Şimdiden teşekkürler. Eğer görevleri getir sonra asla updateTableView
aradığınız gibiTableView veri yüklenemiyor
class TasksTVC: UITableViewController, TaskCellDelegate {
let ref = Firebase(url: URL)
var cell = TaskCell()
var team = ""
var sectionTimes = [String]()
var tasksInSectionArray = [[Task]]()
var tasks = [Task]() {
didSet {
tableView?.reloadData()
}
}
func fetchTasks() {
let tasksRef = Firebase(url: "\(self.ref)/tasks")
tasksRef.queryOrderedByChild("team").queryEqualToValue(team).observeEventType(.Value, withBlock: { snapshot in
var newTasks = [Task]()
for task in snapshot.children {
let tasks = Task(snapshot: task as! FDataSnapshot)
newTasks.append(tasks)
}
self.tasks = newTasks
self.tableView.reloadData()
})
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
fetchTasks()
}
override func viewDidLoad() {
super.viewDidLoad()
updateTableView()
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 44.0
}
func updateTableView() {
sectionTimes = Set(tasks.map{$0.dueTime}).sort()
tasksInSectionArray = sectionTimes.map{section in tasks.filter{$0.dueTime == section}}
print("section times:\(sectionTimes)")
print(tasksInSectionArray)
tableView.reloadData()
}
// MARK: - Table view data source
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return sectionTimes[section]
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return sectionTimes.count
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tasksInSectionArray[section].count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("TaskCell", forIndexPath: indexPath) as! TaskCell
// Configure the cell...
cell.selectionStyle = .None
let task = tasksInSectionArray[indexPath.section][indexPath.row]
cell.label.text = task.title
if task.done == true {
cell.checkBox.image = UIImage(named: "checkedbox")
cell.detailLabel.text = "Completed By: \(task.completedBy)"
}
else {
cell.checkBox.image = UIImage(named: "uncheckedbox")
cell.detailLabel.text = ""
}
cell.delegate = self
return cell
}
}
Eğer reloadData'yı ana sıraya koymak için dispatch_async'i kullanırsanız? –
Hangi reloadData? Updatetableview()? –
Üzgünüm ... Sorguya gönderdiğiniz bloğun içinde demek istedim. Bu çözümle –