I am new to coding and Swift and am now trying to create a small app. I created this part of code:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
let cell = tableView.cellForRowAtIndexPath(indexPath)
var selectedSubject = toBeAddedSubjects[indexPath.row] as Subject
selectedSubject.name = cell.nameLabel
selectedSubject.semester = cell.semesterLabel
if cell?.accessoryType == UITableViewCellAccessoryType.Checkmark {
cell?.accessoryType = UITableViewCellAccessoryType.None;
} else {
cell?.accessoryType = UITableViewCellAccessoryType.Checkmark;
selectedCellsData.append(newElement: selectedSubject)
}
}
I am now getting the error
Type of expression is ambiguous without more context
for cell.nameLabel
and cell.semesterLabel
. These, however, have already been used in a previous piece of code:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("AddSubjectCell", forIndexPath: indexPath) as! SubjectCell
let subject = Subjects[indexPath.row] as Subject
let Semester = "\(subject.semester)"
cell.nameLabel.text = subject.name
cell.semesterLabel.text = "Semester " + Semester
return cell
}
It is my goal to make the append function at the end of the first code work, thus, I need to transform the cell information into the correct type for selectedSubject
.
var selectedCellsData = [ Subject(name: "Initial Subject", semester: 0)]