【问题标题】:UITableView not displaying at runtime when embedded in a Container View嵌入到容器视图中时,UITableView 在运行时不显示
【发布时间】:2016-04-13 18:27:30
【问题描述】:

这是我第一次使用 TableView,我已经遇到了障碍。

我有一个视图控制器,里面有一个容器。 Container View 有一个嵌入的 Table View Controller。我已经使用下面的代码填充了表格视图控制器。我已将数据源和委托设置为表视图控制器,将表视图控制器的自定义类设置为 ORMTableVC,并将表视图单元格标识符设置为 cellIdentifier。

我的问题是在运行时视图控制器是空白的,我看不到任何表格行或数据。

任何帮助将不胜感激。

import Foundation
import UIKit

class ORMTableVC : UITableViewController {




let cellIdentifier = "cellIdentifier"

var Array = [String]()

override func viewDidLoad() {
   super.viewDidLoad()
   Array = ["Reps", "Weight", "RPE", "Fatigue", "Potential Max", "Fatigue Weight"]
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return Array.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let Cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath)

Cell.textLabel?.text = Array[indexPath.row]

return Cell
}




}

StoryBoard Setup

Built App

【问题讨论】:

    标签: ios swift uitableview uicontainerview


    【解决方案1】:

    在浏览了许多教程后设法解决了这个问题。似乎代码不是故事板设置的问题。

    在 Table View Cell 上,标识符需要是 cellIdentifier 而不是 Cell。

    【讨论】:

      猜你喜欢
      • 2016-12-10
      • 2016-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-08
      • 1970-01-01
      • 2020-02-06
      • 1970-01-01
      相关资源
      最近更新 更多