设置WatchKit表

时间:2015-10-03 16:15:16

标签: ios xcode swift uitableview watchkit

我正在尝试将数据加载到WatchKit表中。基本上,使用我所拥有的match数组设置每个表组单元格中match标签的文本。

我已经获得了数据,并且设置了所有内容,但实际上将加载到表中是我遇到的问题

InterfaceController迅速

    var receivedData = Array<Dictionary<String, String>>()

    var eventsListSO = Array<Event>()

    @IBOutlet var rowTable: WKInterfaceTable!

    func doTable() {

        eventsListSO = Event.eventsListFromValues(receivedData)
        rowTable.setNumberOfRows(eventsListSO.count, withRowType: "rows")

        for var i = 0; i < self.rowTable.numberOfRows; i++ {
            let row = rowTable.rowControllerAtIndex(i) as? TableRowController
            for eventm in eventsListSO {
                row!.mLabel.setText(eventm.eventMatch)
                NSLog("SetupTableM: %@", eventm.eventMatch)
            }
        }

    }

我试图在doTable中执行此操作,因为这似乎是最好的地方,我认为doTable设置正确,但我不确定?不确定我是否需要使数组成为可选类型或什么。

如果需要,以下是引用代码:

RowController迅速

class TableRowController {

    @IBOutlet var mLabel: WKInterfaceLabel!
    @IBOutlet var cGroup: WKInterfaceGroup!

}

Event迅速

class Event {

    var eventTColor:String
    var eventMatch:String

    init(dataDictionary:Dictionary<String,String>) {
        eventTColor = dataDictionary["TColor"]!
        eventMatch = dataDictionary["Match"]!
    }

    class func newEvent(dataDictionary:Dictionary<String,String>) -> Event {
        return Event(dataDictionary: dataDictionary)
    }

    class func eventsListFromValues(values: Array<Dictionary<String, String>>) -> Array<Event> {
        var array = Array<Event>()

        for eventValues in values {
            let event = Event(dataDictionary: eventValues)
            array.append(event)
        }

        return array
    }

}

所以我不确定是否:

- doTable设置正确(不能因为eventsListSO.count为空)

2 个答案:

答案 0 :(得分:3)

在WatchKit中使用表格的方式与UIKit有很大不同。

致电setNumberOfRows后,您需要遍历每一行并获取RowController

for var i = 0; i < self.rowTable.numberOfRows; i++ {
    var row = self.rowTable.rowControllerAtIndex(i)
    //setup row here
}

答案 1 :(得分:0)

您可以查看Raywenderlich关于WatchKit的教程:http://www.raywenderlich.com/96741/watchkit-tutorial-with-swift-tables-glances-and-handoff,它教您如何在手表上显示表格,希望这有帮助!