Dav*_*vid 0 xcode uitableview ios swift
我的tableview应用看起来像这样:
我不知道为什么这label1
不起作用。
这是我的操作方法:
我拖动了一个UITableViewController
并将其设置为initialViewController。
我将UITableViewCell样式设置为 Custom
然后我设置UITableViewController的 Custom Class
和UITableViewCell的
然后,我添加了一些约束:
这里是TableViewController.swift
:
import UIKit
class TableViewController: UITableViewController {
let arr = ["abc", "def", "ghi", "jkl", "mno"]
override func viewDidLoad() {
super.viewDidLoad()
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1 // This should more than one if you want to see the sections and rows in your tableview
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arr.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("item", forIndexPath: indexPath) as! TableViewCell
cell.label1.text = arr[indexPath.row]
return cell
}
}
Run Code Online (Sandbox Code Playgroud)
这是 TableViewCell.swift
import UIKit
class TableViewCell: UITableViewCell {
@IBOutlet weak var label1: UILabel!
}
Run Code Online (Sandbox Code Playgroud)
有人知道如何解决吗?我真的需要使用自定义单元格!
PS我正在使用Xcode 7 beta 5,Swift 2.0
小智 5
尝试这个
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1712 次 |
最近记录: |