提问人:parth valia 提问时间:4/27/2023 更新时间:4/27/2023 访问量:70
Swift 拖放功能无法正常工作
swift drag and drop functionality is not working properly
问:
拖放功能无法正常工作,任务无法正确拖放到特定位置。
private func addTaskData(document: [QueryDocumentSnapshot]) {
allTasks.removeAll()
for query in document {
let aTask = Task()
aTask.initWithDict(snapshot: query)
self.allTasks.append(aTask)
sortedArray = self.allTasks.sorted(by: { $0.scheduleDate.timeIntervalSince1970 > $1.scheduleDate.timeIntervalSince1970})
for task in allTasks {
if (currentTasks.contains(where: { $0.title == task.title }))
{
print(task.title,"contain")
}
else
{
if (sortedArray.contains(where: { $0.title == task.title }))
{
print(task.title,"contain")
}
else{
print(task.title,"not contain")
task.scheduleDate = Date()
sortedArray.insert(task, at: 0)
}
}
}
self.allTasks = sortedArray
}
for task in allTasks {
if isPremium{
if nextDateString == "12 AM" {
print("schedule date is past")
if task.isDone == false {
isDateUpdate = true
isUpdateingDateStatus = true
}
}
}
else {
print("schedule date is current or future")
}
}
updateSelectedTasks()
taskTableView.reloadData()
}
这个 moveRowAt 函数第一次完美地执行拖放功能,但第二次我执行拖放时它不起作用。
我认为出现此问题是由于计划日期分配不当,拖放前任务的位置:
并且我已经拖放了“测试 1”任务,它应该是这样的: 但它显示的任务如下:
Test 2 Test 1 Test 3 Test 4 Test 5
Test 2 Test 3 Test 4 Test 1 Test 5
Test 5 Test 1 Test 4 Test 3 Test 2
func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
// Update the model
let movedTask = currentTasks.remove(at: sourceIndexPath.row)
currentTasks.insert(movedTask, at: destinationIndexPath.row)
for (index, task) in currentTasks.enumerated() {
let date = Calendar.current.date(byAdding: .minute, value: index , to: Date())!
task.scheduleDate = date
db.collection(udid).document(task.id).updateData(["scheduleDate": date])
}
// Reload table data
taskTableView.reloadData()
}
答: 暂无答案
评论