以下是該場景。我有一個帶動態單元的UITableViewController。每個單元格都有3個用戶可以點擊的按鈕。在應用程序的另一個地方,我需要用戶看到另一個不可編輯的UITableViewController,並且在用戶看完第一個UITableViewController後單擊它時看到的按鈕具有相同的狀態。將動態表格視圖中按鈕的狀態保存在一個UITableViewController中以在另一箇中查看
換句話說,這是一個歷史頁面。現在第一個UITableViewController有一個UITableViewControllerDataSource,並且我試過對第二個Table View Controller使用相同的數據源,但由於某種原因它不起作用。當用戶在應用程序上向後導航以查看他們最初選擇的第一個UITableViewController時,它將狀態保存得很好,但是當它們到達應用程序的末尾時,新的UITableViewController具有所有新(未選定)狀態那些按鈕。
我還需要第二次的UITableViewController有不同的顏色和其他一些小的差異爲第一,但現在我最關心的是確保我可以從前面訪問這些國家。
這裏是我的數據源:
class DepressedButtonTableViewControllerDataSource: NSObject, UITableViewDataSource, DepressedSelectionTableViewCellDelegate {
//MARK: Array for putting in my selections, and some other important variabls for managing choices
var choices: Array<Int> = []
var result = 0
var advanceArray: Array<Int> = []
// MARK: - Table view data source
func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return 3
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "depressedSelection", for: indexPath) as! DepressedSelectionTableViewCell
let firstThing = "placeholder"
let secondThing = "other texxt"
let thirdThing = "multiple lines! look ma! look at this!"
let cellData = [firstThing, secondThing, thirdThing]
let text = cellData[indexPath.row]
cell.cellText.text = text
//configure muh buttons
cell.yes.setImage(#imageLiteral(resourceName: "yes_unselected"), for: .normal)
cell.yes.setImage(#imageLiteral(resourceName: "yes_selected"), for: .selected)
cell.no.setImage(#imageLiteral(resourceName: "no_unselected"), for: .normal)
cell.no.setImage(#imageLiteral(resourceName: "no_selected"), for: .selected)
cell.na.setImage(#imageLiteral(resourceName: "na_unselected"), for: .normal)
cell.na.setImage(#imageLiteral(resourceName: "na_selected"), for: .selected)
cell.delegate = self
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
//delegate code
func filledOut(controller: DepressedSelectionTableViewCell, selections: Int!, isClicked: Bool!) {
choices.append(selections)
if isClicked == true {
advanceArray.append(1)
}
if advanceArray.count == 3 {
print(choices.reduce(0, +))
result = (choices.reduce(0, +))
print(advanceArray.count)
NotificationCenter.default.post(name: Notification.Name("TableViewToDepressedParent"), object: nil)
}
}
}
請編輯您的問題,包括相關的代碼 – Paulw11
謝謝你,我已經包含了相關的代碼 –