Thanks, Caroline. Hereās where I got to so far:
-
MondayWeekALessons (list of lessons on Monday)
-
Monday cell
-
Lesson.swift file
-
LessonSampleData.swift file. In 3) I do not wish to use the data I have placed here but I wish to keep the structure which is displayed with 4 Labels.
-
import UIKit
class MWALessonsViewController: UITableViewController {
var lessons:[Lesson] = []
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func editingRow(sender: UIBarButtonItem) {
self.editing = !self.editing
}
// Override to support conditional editing of the table view.
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
// Override to support editing the table view.
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
self.lessons.removeAtIndex(indexPath.row)
// Delete the row from the data source
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
} else if editingStyle == .Insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
// Override to support rearranging the table view.
override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {
let itemToMove = lessons[fromIndexPath.row]
lessons.removeAtIndex(fromIndexPath.row)
lessons.insert(itemToMove, atIndex: toIndexPath.row)
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return lessons.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("MWALessonsCell", forIndexPath: indexPath) as! MWALessonsCell
let lesson = lessons[indexPath.row] as Lesson
cell.lesson = lesson
return cell
}
override func viewDidAppear(animated: Bool) {
let nav = self.navigationController?.navigationBar
nav?.barStyle = UIBarStyle.Default
nav?.tintColor = UIColor.cyanColor()
let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 45, height: 45))
imageView.contentMode = .ScaleAspectFit
let image = UIImage(named: "MCButton")
imageView.image = image
navigationItem.titleView = imageView
}
@IBAction func backToLessonsViewController(segue:UIStoryboardSegue) {
}
@IBAction func saveLessonDetail(segue:UIStoryboardSegue) {
if let mwaLessonDetailsViewController = segue.sourceViewController as? MWALessonDetailsViewController {
if let lesson = mwaLessonDetailsViewController.lesson {
lessons.append(lesson)
let indexPath = NSIndexPath(forRow: lessons.count-1, inSection: 0)
tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
}
}
}
-
import UIKit
class MWALessonsCell: UITableViewCell {
@IBOutlet weak var timeLabel: UILabel!
@IBOutlet weak var subjectLabel: UILabel!
@IBOutlet weak var placeLabel: UILabel!
@IBOutlet weak var homeworkDayLabel: UILabel!
var lesson: Lesson! {
didSet {
timeLabel.text = lesson.time
subjectLabel.text = lesson.subject
placeLabel.text = lesson.place
homeworkDayLabel.text = lesson.homeworkDay
}
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
-
import UIKit
struct Lesson {
var time: String?
var subject: String?
var place: String?
var homeworkDay: String?
init(time: String?, subject: String?, place: String?, homeworkDay: String?){
self.time = time
self.subject = subject
self.place = place
self.homeworkDay = homeworkDay
}
}
-
import Foundation
let lessonsData = [
Lesson(time: ā8.20amā, subject: āHomeroomā, place: āRoom S2ā, homeworkDay: āā) ]