【发布时间】:2020-08-13 09:34:01
【问题描述】:
我是 iOS 开发新手,需要您的帮助。
我正在使用 UITableView 来构建任务表。任务数据从 Firebase 数据库传输。当我单击任务单元格上的按钮时,会打开模态弹出窗口(在同一个 ViewController 中通过 animate 方法)。
我想访问模态弹出窗口的元素,以便将特定任务的数据从数据库传递到其模态窗口。
我有包含所有单元格元素出口的 TaskViewCell 文件,例如 previewTitleLabel、previewMotivLabel 等。
TasksListScreen 文件:
import UIKit
import Firebase
import FirebaseAuth
import FirebaseFirestore
class TasksListScreen: UIViewController {
var db = Firestore.firestore()
var tasksArray = [Task]() // array of tasks using Task struct
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var centerPopupConstraint: NSLayoutConstraint!
@IBOutlet weak var backgroundButton: UIButton!
// show popup
@IBAction func yesButtonTapped(_ sender: Any) {
centerPopupConstraint.constant = 0 // popup appear
// add slide animation for popup
UIView.animate(withDuration: 0.3, animations: {
self.view.layoutIfNeeded()
self.backgroundButton.alpha = 0.5
})
}
// done button on popup is clicked
@IBAction func closePopup(_ sender: Any) {
centerPopupConstraint.constant = -450 // popup disappear
// add slide animation for popup
UIView.animate(withDuration: 0.1, animations: {
self.view.layoutIfNeeded()
self.backgroundButton.alpha = 0
})
}
}
extension TasksListScreen: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tasksArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "taskCell") as! TaskViewCell
let task = tasksArray[indexPath.row]
cell.previewTitleLabel.text = task.title
cell.previewMotivLabel.text = task.tip
cell.previewHashtagsLabel.text = task.hashtags
// Here I want to access task's modal window to pass data to its elements:
// the same task title and task description form database
}}
请帮忙!!
TasksListScreen storyboard with modal popup
【问题讨论】:
标签: ios swift firebase uitableview