(Swift) 在 ViewController 的容器视图中显示表 ViewController

(Swift) Show TableViewController in a ViewController's Container view

我正在尝试让 table 视图控制器显示在视图控制器内的容器视图内。这是我的故事板设置:

这些是我的 swift 文件:

这是我的页面浏览滑动的一些代码:

  func getStepZero() -> ProfileViewController {
    return storyboard!.instantiateViewControllerWithIdentifier("ProfileView") as! ProfileViewController
  }

  func getStepOne() -> HomeViewController {
    return storyboard!.instantiateViewControllerWithIdentifier("HomeView") as! HomeViewController
  }

  func getStepTwo() -> MatchesSegueViewController {
    return storyboard!.instantiateViewControllerWithIdentifier("MatchesSegueView") as! MatchesSegueViewController
  }

  func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {

    if viewController.isKindOfClass(MatchesSegueViewController) {
      // 2 -> 1
      return getStepOne()
    } else if viewController.isKindOfClass(HomeViewController) {
      // 1 -> 0
      return getStepZero()
    } else {
      // 0 -> end of the road
      return nil
    }
  }

  func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {

    if viewController.isKindOfClass(ProfileViewController) {
      // 0 -> 1
      return getStepOne()
    } else if viewController.isKindOfClass(HomeViewController) {
      // 1 -> 2
      return getStepTwo()
    } else {
      // 2 -> end of the road
      return nil
    }
  }

table查看代码:

class MatchTableViewController: UITableViewController {

  let cellId = "cellId"

override func viewDidLoad() {
    super.viewDidLoad()

    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = false

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    // #warning Incomplete implementation, return the number of sections
    return 0
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of rows
    return 5
}


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    // line below comes with function
    //let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath)

    // Configure the cell...
    // lines below are from YouTube tutorial
  let cell = UITableViewCell(style: .Subtitle, reuseIdentifier: cellId)
  cell.textLabel?.text = "DUMMY TEXT"

    return cell
}

我有一个页面视图控制器,所以当我向右滑动时,我会转到我的视图控制器,它应该会通过嵌入的转场立即转至我的 table 视图控制器(希望转场不会被看到)。我怎样才能做到这一点?当我向右滑动时,它显示了一个空的 table 视图,尽管它应该显示一些虚拟数据单元格。

非常感谢任何帮助。

根据您的代码,

更改 tableViewController 的这一部分

 override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
      return 0
 }

对此

 override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
      return 1
 }