Learn watchOS Programming!
Communication Channel Google Document for live chat - http://tiny.cc/watchOSTechTalk Github link for the project - https://github.com/patilsnehal/watchOSTableview
Create watchOS Application with tableview
Create Project
Add tableview
Change the color of the global tint
Change Identifier
Add Group and then labels to it
Change font, alignment etc
Add a watchKit class
ScheduleInterfaceController
Change the class type as ScheduleInterfaceController
Lets do some coding finally :) Connect table @IBOutlet var WWCMeetupTable: WKInterfaceTable! Set up Number of rows WWCMeetupTable.setNumberOfRows(10, withRowType: "WWCRow");
Hit Run !
MeetupRowController
Change the class type as MeetupRowController
Add meetup.json and meetup.swift (Shared folder) [ { "startTime": "10:00 AM", "endTime": "12:00 PM", "title": "Python Meetup", }, { "startTime": "12:00 PM", “endTime": "2:00 PM", "title": "iOS Meetup", }, { "startTime": "2:00 PM", "endTime": "4:00 PM", "title": "WatchOS Meetup", }, { "startTime": "4:00 PM", "endTime": "6:00 PM", "title": "Android Meetup", }, { "startTime": "6:00 PM", "endTime": "8:00 PM", "title": "Java Meetup", } ] class Meetup { let title: String let starttime: String let endtime: String class func allMeetups() -> [Meetup] { var meetups = [Meetup]() if let path = NSBundle.mainBundle().pathForResource("Meetup", ofType: "json"), let data = NSData(contentsOfFile: path) { do { let json = try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments) as! [Dictionary<String, String>] for dict in json { let meetup = Meetup(dictionary: dict) meetups.append(meetup) } } catch { print(error) } } return meetups } init( title: String, starttime: String, endtime: String) { self.title = title self.starttime = starttime self.endtime = endtime } convenience init(dictionary: [String: String]) { let title = dictionary["title"]! let starttime = dictionary["startTime"]! let endtime = dictionary["endTime"]! self.init(title: title, starttime: starttime, endtime: endtime)
Add files and add them to app and extension target
Configure the labels on MeetupRowController class MeetupRowController: NSObject { @IBOutlet var timeLabel: WKInterfaceLabel! @IBOutlet var titleLabel: WKInterfaceLabel! // 1 var meetup: Meetup? { // 2 Add a property observer that is triggered whenever the property is set; didSet { // 3 Check of meetup is not nil if let meetup = meetup { // 4 configure the labels using the relevant properties of meetup timeLabel.setText(meetup.starttime) titleLabel.setText(meetup.title) } } } }
ScheduleInterfaceController var meetups = Meetup.allMeetups() override func awakeWithContext(context: AnyObject?) { super.awakeWithContext(context) // Set up a Row count WWCMeetupTable.setNumberOfRows(meetups.count, withRowType: "WWCRow"); // Add data for each row for index in 0..<WWCMeetupTable.numberOfRows { if let controller = WWCMeetupTable.rowControllerAtIndex(index) as? MeetupRowController { controller.meetup = meetups[index] } } }
Hit Run!
Add new Interface controller and add design it. ● Change Identifier and name it as “Meetup” ● Copy a image called static maps into the project and assign it to the image. ● Create a group and add 2 buttons to it - YES & NO
MeetupInterfaceController class MeetupInterfaceController: WKInterfaceController { @IBOutlet var timeLabel: WKInterfaceLabel! @IBOutlet var titleLabel: WKInterfaceLabel! // 1 var meetup: Meetup? { // 2 didSet { // 3 if let meetup = meetup { // 4 timeLabel.setText("(meetup.starttime) to (meetup.endtime)") titleLabel.setText(meetup.title) } } } override func awakeWithContext(context: AnyObject?) { super.awakeWithContext(context) if let meetup = context as? Meetup { self.meetup = meetup } } }
ScheduleInterfaceController Add a method didSelectRowAtIndex to push a viewcontroller override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) { let meetup = meetups[rowIndex] presentControllerWithName("Meetup", context: meetup) }
Hit Run!
Learn watchOS Programming!
Learn watchOS Programming!

Learn watchOS Programming!

  • 1.
  • 2.
    Communication Channel Google Documentfor live chat - http://tiny.cc/watchOSTechTalk Github link for the project - https://github.com/patilsnehal/watchOSTableview
  • 3.
  • 4.
  • 5.
  • 6.
    Change the colorof the global tint
  • 7.
  • 8.
    Add Group andthen labels to it
  • 9.
  • 10.
  • 11.
  • 12.
    Change the classtype as ScheduleInterfaceController
  • 13.
    Lets do somecoding finally :) Connect table @IBOutlet var WWCMeetupTable: WKInterfaceTable! Set up Number of rows WWCMeetupTable.setNumberOfRows(10, withRowType: "WWCRow");
  • 14.
  • 15.
  • 16.
    Change the classtype as MeetupRowController
  • 17.
    Add meetup.json andmeetup.swift (Shared folder) [ { "startTime": "10:00 AM", "endTime": "12:00 PM", "title": "Python Meetup", }, { "startTime": "12:00 PM", “endTime": "2:00 PM", "title": "iOS Meetup", }, { "startTime": "2:00 PM", "endTime": "4:00 PM", "title": "WatchOS Meetup", }, { "startTime": "4:00 PM", "endTime": "6:00 PM", "title": "Android Meetup", }, { "startTime": "6:00 PM", "endTime": "8:00 PM", "title": "Java Meetup", } ] class Meetup { let title: String let starttime: String let endtime: String class func allMeetups() -> [Meetup] { var meetups = [Meetup]() if let path = NSBundle.mainBundle().pathForResource("Meetup", ofType: "json"), let data = NSData(contentsOfFile: path) { do { let json = try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments) as! [Dictionary<String, String>] for dict in json { let meetup = Meetup(dictionary: dict) meetups.append(meetup) } } catch { print(error) } } return meetups } init( title: String, starttime: String, endtime: String) { self.title = title self.starttime = starttime self.endtime = endtime } convenience init(dictionary: [String: String]) { let title = dictionary["title"]! let starttime = dictionary["startTime"]! let endtime = dictionary["endTime"]! self.init(title: title, starttime: starttime, endtime: endtime)
  • 18.
    Add files andadd them to app and extension target
  • 19.
    Configure the labelson MeetupRowController class MeetupRowController: NSObject { @IBOutlet var timeLabel: WKInterfaceLabel! @IBOutlet var titleLabel: WKInterfaceLabel! // 1 var meetup: Meetup? { // 2 Add a property observer that is triggered whenever the property is set; didSet { // 3 Check of meetup is not nil if let meetup = meetup { // 4 configure the labels using the relevant properties of meetup timeLabel.setText(meetup.starttime) titleLabel.setText(meetup.title) } } } }
  • 20.
    ScheduleInterfaceController var meetups =Meetup.allMeetups() override func awakeWithContext(context: AnyObject?) { super.awakeWithContext(context) // Set up a Row count WWCMeetupTable.setNumberOfRows(meetups.count, withRowType: "WWCRow"); // Add data for each row for index in 0..<WWCMeetupTable.numberOfRows { if let controller = WWCMeetupTable.rowControllerAtIndex(index) as? MeetupRowController { controller.meetup = meetups[index] } } }
  • 21.
  • 22.
    Add new Interfacecontroller and add design it. ● Change Identifier and name it as “Meetup” ● Copy a image called static maps into the project and assign it to the image. ● Create a group and add 2 buttons to it - YES & NO
  • 23.
    MeetupInterfaceController class MeetupInterfaceController: WKInterfaceController{ @IBOutlet var timeLabel: WKInterfaceLabel! @IBOutlet var titleLabel: WKInterfaceLabel! // 1 var meetup: Meetup? { // 2 didSet { // 3 if let meetup = meetup { // 4 timeLabel.setText("(meetup.starttime) to (meetup.endtime)") titleLabel.setText(meetup.title) } } } override func awakeWithContext(context: AnyObject?) { super.awakeWithContext(context) if let meetup = context as? Meetup { self.meetup = meetup } } }
  • 24.
    ScheduleInterfaceController Add a methoddidSelectRowAtIndex to push a viewcontroller override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) { let meetup = meetups[rowIndex] presentControllerWithName("Meetup", context: meetup) }
  • 25.