我正在尝试让一个tableview控制器显示在视图控制器内部的容器视图中。这是我的故事板设置:
这些是我的快速文件:
以下是我的网页浏览功能的一些代码:
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
}
}
tableview代码:
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
}
我有一个页面视图控制器,所以当我向右滑动时,我会转到我的视图控制器,它应该通过嵌入segue立即转到我的表视图控制器(希望不会看到segue)。我怎么能做到这一点?当我向右滑动时,它向我显示一个空表视图,即使它应该显示一些虚拟数据单元格。
非常感谢任何帮助。
答案 0 :(得分:1)
从您的代码中
更改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
}