我正在尝试让 TableView Controller 显示在 View Controller 内的容器 View 内。这是我的 Storyboard设置:
这些是我的 swift 文件:
这是我的页面 View 滑动的一些代码:
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
}
}
表格 View 代码:
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
}
我有一个页面 View Controller ,所以当我向右滑动时,我会转到我的 View Controller ,它应该立即通过嵌入转场连接到我的 TableView Controller (希望转场不会被看到)。我怎样才能做到这一点?当我向右滑动时,它会显示一个空的表格 View ,尽管它应该显示一些虚拟数据单元格。
非常感谢任何帮助。
最佳答案
根据您的代码,
更改 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
}
关于swift - (Swift) 在 ViewController 的容器 View 中显示 TableViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38472161/