1

I have a table that displays a list of pupils and their chosen subjects. The pupil's name are displayed as table section headers and each chosen subject is displayed as table rows for each section. I have a simple class to store the pupil's name as a string and their subjects as an array as follows:

import UIKit

class TableText: NSObject {

var name: String

var subject: [String]

init(name: String, subject: [String]) {
    self.name = name
    self.subject = subject

 }

}

In my custom TableViewCell I have a didSet property observer to track any changes to each pupil's chosen subjects (i.e. I have a textView that the user can click on and modify or change a subject. My didSet is currently as follows:

var tableText: TableText? {

    didSet {

        let mySubject = myTextView.text
        if ((tableText?.subject.contains(mySubject)) != nil) {          
        }          
    }
}

My cellForRowAtIndexPath in my TableViewController is as follows:

 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
   let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! myTableViewCell

   cell.delegate = self

    let pupil = tableTexts[indexPath.section]

    cell.myTextView.text = pupil.subject[indexPath.row]

    cell.subject = pupil.subject[indexPath.row]
    cell.name = pupil.name
    print("name: \(cell.name) subject: \(cell.subject)")

    return cell
}

I'm puzzled at how to take the data from the tableView of each pupil and pupil's subjects and use didSet to set the pupil's name and list of subjects so I can monitor the textViews and update changes to the model as required. I much appreciate any assistance.

4

0 に答える 0