嗨,我想填充这个表格视图。
我没有使用静态表视图,因为出现错误,我决定使用动态表视图并禁用表格中的滚动。 该表格视图仅用于信息展示:
@IBOutlet var tableInfoQuake: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = quake.place
tableInfoQuake.cellForRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 0))?.textLabel?.text = quake.place
tableInfoQuake.cellForRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 0))?.textLabel?.text = "Mag: \(quake.mag)"
tableInfoQuake.cellForRowAtIndexPath(NSIndexPath(forRow: 1, inSection: 0))?.textLabel?.text = "Cordinate: (\(quake.longitude),\(quake.latitude))"
tableInfoQuake.cellForRowAtIndexPath(NSIndexPath(forRow: 1, inSection: 0))?.textLabel?.text = "Depth: \(quake.depth)"
但在表格视图中我没有看到任何东西。
我该怎么做?谢谢。
编辑:我这样做来修改每一行:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cellIdentifier = "quakeInfo"
var cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as UITableViewCell
if indexPath == NSIndexPath(forRow: 0, inSection: 0){
cell.textLabel!.text = quake.place
cell.detailTextLabel!.text = "Mag: \(quake.mag)"
}
if indexPath == NSIndexPath(forRow: 1, inSection: 0){
cell.textLabel!.text = "Cordinate: (\(quake.longitude),\(quake.latitude))"
cell.detailTextLabel!.text = "Depth: \(quake.depth)"
}
return cell
}
datasource
更改为dataSource
的大小写。 - Nebrilframe: CGRect(x:0, y:0, width:200, height:50)
。 - Christopher Klaus