【问题标题】:How to manage a table view that is a subview in swift如何快速管理作为子视图的表视图
【发布时间】:2014-09-17 17:54:58
【问题描述】:

在我的一个场景中,我在视图中有一个表格视图(和另一个视图)。由于我的表视图不是外部视图,我不能使用 UITableViewController 来处理表视图。我将如何管理表格视图?

感谢您的帮助!

包含表格的视图的当前视图控制器:

class CViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

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

【问题讨论】:

    标签: uitableview layout ios7 uiviewcontroller


    【解决方案1】:

    你需要实现 UITableViewDelegate 和 UITableViewDataSource。您还需要确保 tableView 指向您的 Viewcontroller 的 Delegate 和 DataSource。您可以在 Interface Builder 中执行此操作。

    class CViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    
    override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // return the number of rows
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) ->       UITableViewCell{
    
    // create your cells
    }
    
    }
    

    【讨论】:

    • 我完全忘记了这样做:“您还需要确保 tableView 指向您的代表和数据源的 Viewcontroller。”谢谢大佬!
    • 如何将 tableView 指向 Delegate 和 Datasource 的 Viewcontroller?
    【解决方案2】:

    我不知道 swift,但一般来说,如果你想管理一个表格视图,那么你可以实现 UITableViewDelegate 和 UITableViewDataSource 的方法。

    【讨论】:

    • 但是这些协议不能与我实现的常规 UIViewController 一起使用。不过谢谢你的回答:)
    • 我不明白,为什么不呢?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-22
    • 2016-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-09
    • 1970-01-01
    相关资源
    最近更新 更多