【问题标题】:Apple Watch Table - first 4 rows not appearingApple Watch Table - 前 4 行未出现
【发布时间】:2015-03-19 14:27:33
【问题描述】:

我在 Apple Watch 上向 WKInterfaceTable 添加行时遇到问题。奇怪的是,无论我做什么,前 4 行都显示为空。我尝试手动并循环添加行 - 没关系。我相信我的代码很好,因为第 5 行和更多行看起来都很好。以下是发生的事情:

进一步滚动:

我的代码:

import Foundation
import WatchKit

class TableInterfaceController: WKInterfaceController{

    @IBOutlet weak var agentTable: WKInterfaceTable!

    let agents = ["The Dude","Walter","Donnie","Maude","Knox","Karl","Nihilist 2"]

    override init(){
        super.init()
        loadTableData()
    }


    private func loadTableData(){
        agentTable.setNumberOfRows(agents.count, withRowType: "AgentTableRowController")
        println("Count: \(agents.count)")

        for(index,agentName) in enumerate(agents){
            let row = agentTable.rowControllerAtIndex(index) as AgentTableRowController
            println(agentName, index)
            row.agentLabel.setText(agentName)
        }
    }
}

任何帮助表示赞赏。这可能是一件微不足道的事情。我在 Yosemite 10.10.2 上运行 Xcode 6.2 (6C131e)

【问题讨论】:

标签: ios swift watchkit apple-watch wkinterfacetable


【解决方案1】:

awakeWithContext 中初始化我的表时,我遇到了完全相同的问题。按照 dan 的建议,通过将我的表初始化移动到 willActivate,问题得到了解决。

我筛选了WKInterfaceControllerWKInterfaceTable 的文档,他们建议您应该能够在initawakeWithContext 中执行初始化,所以我相信这是WatchKit 框架中的一个错误。

【讨论】:

    【解决方案2】:

    也许用索引的for循环试试?

    for var i=0; i<agents.count; i++ {
       let row = agentTable.rowControllerAtIndex(i) as AgentTableRowController
            println(agents[i], i)
            row.agentLabel.setText(agents[i])
    }
    

    希望对你有用..

    【讨论】:

    • 没有骰子,我什至试过这个:` let row = agentTable.rowControllerAtIndex(0) as AgentTableRowController row.agentLabel.setText("Agent1")` 没有用。
    • agents.count 如果您在 init() 中 println 它会为您提供正确的值?
    • 是的,一切都是一流的。所有索引,值打印正确。前 4 行只是没有填充。也许这是一个错误。
    • 如果让 row = agentTable.rowControllerAtIndex(i) 为? AgentTableRowController {row.agentLabel.setText(agents[i]) }。试试这个
    猜你喜欢
    • 1970-01-01
    • 2020-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    相关资源
    最近更新 更多