cs193p – Project #3 Assignment #3 Task #6

By Qniemiec (Own work) [CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0) or GFDL (http://www.gnu.org/copyleft/fdl.html)], via Wikimedia Commons

Please note, this blog entry is from a previous course. You might want to check out the current one.

Anytime a graph is on screen, a description of what it is being drawn should also be shown on screen somewhere sensible, e.g., if sin(M) is what is being graphed, then the string “sin(M)” should be on screen somewhere.

Prepare for the segue firing when the graph button gets pressed. For the “normal” iPhone view the destination of the segue is its designated destination view controller, for the split view it is the visible view controller of the second navigation view controller. If the destination is the graph view controller and the segue is the one originating from the graph button set the new title. To get the last part of the description of the current program, create an array of its parts and use only the last one:

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        var destination = segue.destinationViewController as? UIViewController
        if let nc = destination as? UINavigationController {
            destination = nc.visibleViewController
        if let gvc = destination as? GraphViewController {
            if let identifier = segue.identifier {
                switch identifier {
                case "plot graph":
                    gvc.title = brain.description == "" ? "Graph" :
                        brain.description.componentsSeparatedByString(", ").last

The complete code for the task #6 is available on GitHub.


Flattr this!

Leave a Reply

Your email address will not be published. Required fields are marked *