-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
209 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import UIKit | ||
|
||
protocol ListDetailViewControllerDelegate: class { | ||
func listDetailViewControllerDidCancel(controller: ListDetailViewController) | ||
|
||
func listDetailViewController(controller: ListDetailViewController, didFinishAddingChecklist checklist: Checklist) | ||
func listDetailViewController(controller: ListDetailViewController, didFinishEditingChecklist checklist: Checklist) | ||
} | ||
|
||
class ListDetailViewController: UITableViewController, UITextFieldDelegate { | ||
|
||
@IBOutlet weak var textField: UITextField! | ||
@IBOutlet weak var doneBarButton: UIBarButtonItem! | ||
|
||
weak var delegate: ListDetailViewControllerDelegate? | ||
|
||
var checklistToEdit: Checklist? | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
if let checklist = checklistToEdit { | ||
title = "Edit Checklist" | ||
textField.text = checklist.name | ||
doneBarButton.enabled = true | ||
} | ||
} | ||
|
||
override func viewWillAppear(animated: Bool) { | ||
super.viewWillAppear(animated) | ||
textField.becomeFirstResponder() | ||
} | ||
|
||
@IBAction func cancel() { | ||
delegate?.listDetailViewControllerDidCancel(self) | ||
} | ||
|
||
@IBAction func done() { | ||
if let checklist = checklistToEdit { | ||
checklist.name = textField.text! | ||
delegate?.listDetailViewController(self, didFinishEditingChecklist: checklist) | ||
} else { | ||
let checklist = Checklist(name: textField.text!) | ||
delegate?.listDetailViewController(self, didFinishAddingChecklist: checklist) | ||
} | ||
} | ||
|
||
override func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? { | ||
return nil | ||
} | ||
|
||
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool { | ||
let oldText: NSString = textField.text! | ||
let newText: NSString = oldText.stringByReplacingCharactersInRange(range, withString: string) | ||
doneBarButton.enabled = (newText.length > 0) | ||
return true | ||
} | ||
} | ||
|