Learn WatchKit for iOS by Kim Topley

Learn WatchKit for iOS by Kim Topley

Author:Kim Topley
Language: eng
Format: epub, pdf
Publisher: Apress, Berkeley, CA


Presenting the Configuration Controller

As you’ve seen, if you run the application and press the Configure button, the configuration controller is presented. The presentation happens automatically because we added a modal segue to the Configure button in the storyboard. However, at this point, we’re not passing context information to the controller. Because the controller is presented by a segue, we can’t pass the context object directly to it. Instead, as you saw in Chapter 5, we need to implement the contextForSegueWithIdentifier() method in the presenting controller. To do that, add the following code near the bottom of the InterfaceController class:

override func contextForSegueWithIdentifier(

segueIdentifier: String) -> AnyObject? {

return ConfigurationController.ControllerContext(

textAttributes: textAttributes,

callback: onCallBack)

}

func onCallBack(textAttributes: TextAttributes) -> Void {

The context object is an instance of the ControllerContext class, which we initialize with the current text attributes from the controller’s textAttributes property, and a reference to the onCallBack method, which the presenting controller will call to pass back the new attributes. To check that this is working, open ConfigurationController.swift in the editor and add the following line of code to its awakeWithContext() method:

override func awakeWithContext(context: AnyObject?) {

super.awakeWithContext(context)

// Configure interface objects here.

println("Context: \(context)")

}

Now run the application and press the Configure button. When the configuration controller appears, you should see something like this in the Xcode console:

Context: Optional(Configuration_Table_WatchKit_Extension.ConfigurationController.ControllerContext)



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.