【问题标题】:UItableview using swift language [closed]使用 swift 语言的 UItableview [关闭]
【发布时间】:2014-10-02 12:08:27
【问题描述】:

我在 xcode 6 中为 UITableview 使用目标 c 代码,但我想将目标 c 代码替换为 swift 语言

【问题讨论】:

  • 您在哪里尝试 Swift 代码?这不是一个为你编写代码的网站。
  • 如果您在 Swift 中创建 UITableViewController 的子类,大部分代码都会自动为您创建。同样正如@Zaph 所提到的,向我们展示您迄今为止所做的尝试,我们可以为您提供帮助。
  • 也许这是一个学习 Swift 的好机会?

标签: objective-c swift ios8


【解决方案1】:

从默认的UITableViewController子类模板复制并粘贴(文件>新建>文件>iOS>源>可可触摸类>将超类设置为UITableViewController):

override func numberOfSectionsInTableView(tableView: UITableView!) -> Int {
    // #warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 0
}

override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 0
}

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
    let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as UITableViewCell

    // Configure the cell...

    return cell
}

在 Swift 文件中创建 UITableViewController 的子类,并根据您的需要调整代码。

【讨论】:

    最近更新 更多