diff --git a/AllListsViewController.swift b/AllListsViewController.swift new file mode 100644 index 0000000..38f76b6 --- /dev/null +++ b/AllListsViewController.swift @@ -0,0 +1,47 @@ +import UIKit + +class AllListsViewController: UITableViewController { + + var lists = [ + Checklist(name: "Birthdays"), + Checklist(name: "Groceries"), + Checklist(name: "Cool Apps"), + Checklist(name: "To Do") + ] + + override func viewDidLoad() { + super.viewDidLoad() + } + + override func didReceiveMemoryWarning() { + super.didReceiveMemoryWarning() + } + + override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return lists.count + } + + override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { + let cell = cellForTableView(tableView) + + let checklist = lists[indexPath.row] + cell.textLabel!.text = checklist.name + cell.accessoryType = .DetailDisclosureButton + + return cell + } + + override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { + let checklist = lists[indexPath.row] + performSegueWithIdentifier("ShowChecklist", sender: checklist) + } + + func cellForTableView(tableView: UITableView) -> UITableViewCell { + let cellIdentifier = "Cell" + if let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) { + return cell + } else { + return UITableViewCell(style: .Default, reuseIdentifier: cellIdentifier) + } + } +} diff --git a/Checklists.xcodeproj/project.pbxproj b/Checklists.xcodeproj/project.pbxproj index 68677b6..ee46302 100644 --- a/Checklists.xcodeproj/project.pbxproj +++ b/Checklists.xcodeproj/project.pbxproj @@ -14,6 +14,8 @@ A81172CF1CD0660F00BA3196 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A81172CD1CD0660F00BA3196 /* LaunchScreen.storyboard */; }; A81172D91CD0859800BA3196 /* ChecklistItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = A81172D81CD0859800BA3196 /* ChecklistItem.swift */; }; A8961D4F1CD19E87006AFAF4 /* ItemDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8961D4E1CD19E87006AFAF4 /* ItemDetailViewController.swift */; }; + A8961D541CD309B0006AFAF4 /* AllListsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8961D531CD309B0006AFAF4 /* AllListsViewController.swift */; }; + A8961D561CD31108006AFAF4 /* Checklist.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8961D551CD31108006AFAF4 /* Checklist.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -26,6 +28,8 @@ A81172D01CD0660F00BA3196 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; A81172D81CD0859800BA3196 /* ChecklistItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChecklistItem.swift; sourceTree = ""; }; A8961D4E1CD19E87006AFAF4 /* ItemDetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = ItemDetailViewController.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + A8961D531CD309B0006AFAF4 /* AllListsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AllListsViewController.swift; path = ../AllListsViewController.swift; sourceTree = ""; }; + A8961D551CD31108006AFAF4 /* Checklist.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Checklist.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -58,6 +62,7 @@ A81172C31CD0660E00BA3196 /* Checklists */ = { isa = PBXGroup; children = ( + A8961D531CD309B0006AFAF4 /* AllListsViewController.swift */, A81172C41CD0660E00BA3196 /* AppDelegate.swift */, A81172C61CD0660E00BA3196 /* ChecklistViewController.swift */, A81172C81CD0660E00BA3196 /* Main.storyboard */, @@ -65,6 +70,7 @@ A81172CD1CD0660F00BA3196 /* LaunchScreen.storyboard */, A81172D01CD0660F00BA3196 /* Info.plist */, A81172D81CD0859800BA3196 /* ChecklistItem.swift */, + A8961D551CD31108006AFAF4 /* Checklist.swift */, A8961D4E1CD19E87006AFAF4 /* ItemDetailViewController.swift */, ); path = Checklists; @@ -144,7 +150,9 @@ files = ( A81172C71CD0660E00BA3196 /* ChecklistViewController.swift in Sources */, A8961D4F1CD19E87006AFAF4 /* ItemDetailViewController.swift in Sources */, + A8961D561CD31108006AFAF4 /* Checklist.swift in Sources */, A81172D91CD0859800BA3196 /* ChecklistItem.swift in Sources */, + A8961D541CD309B0006AFAF4 /* AllListsViewController.swift in Sources */, A81172C51CD0660E00BA3196 /* AppDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Checklists/Base.lproj/Main.storyboard b/Checklists/Base.lproj/Main.storyboard index af577b5..3879634 100644 --- a/Checklists/Base.lproj/Main.storyboard +++ b/Checklists/Base.lproj/Main.storyboard @@ -6,6 +6,28 @@ + + + + + + + + + + + + + + + + + + + + + + @@ -45,7 +67,7 @@ - + @@ -127,12 +149,12 @@ - + - + diff --git a/Checklists/Checklist.swift b/Checklists/Checklist.swift new file mode 100644 index 0000000..0193289 --- /dev/null +++ b/Checklists/Checklist.swift @@ -0,0 +1,10 @@ +import UIKit + +class Checklist: NSObject { + var name: String + + init(name: String) { + self.name = name + super.init() + } +} diff --git a/Checklists/ChecklistItem.swift b/Checklists/ChecklistItem.swift index 1da4e86..c76613b 100644 --- a/Checklists/ChecklistItem.swift +++ b/Checklists/ChecklistItem.swift @@ -15,6 +15,7 @@ class ChecklistItem: NSObject, NSCoding { required init?(coder aDecoder: NSCoder) { text = aDecoder.decodeObjectForKey("Text") as! String checked = aDecoder.decodeBoolForKey("Checked") + super.init() } diff --git a/Checklists/ChecklistViewController.swift b/Checklists/ChecklistViewController.swift index 4e498e8..81cf71d 100644 --- a/Checklists/ChecklistViewController.swift +++ b/Checklists/ChecklistViewController.swift @@ -17,6 +17,8 @@ class ChecklistViewController: UITableViewController, ItemDetailViewControllerDe ChecklistItem(text: "Eat ice cream", checked: false) ] + var checklist: Checklist! + required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) loadChecklistItems() @@ -41,7 +43,7 @@ class ChecklistViewController: UITableViewController, ItemDetailViewControllerDe override func viewDidLoad() { super.viewDidLoad() - // Do any additional setup after loading the view, typically from a nib. + title = checklist.name } override func didReceiveMemoryWarning() {