Multiple UITableview in Single Viewcontroller

后端 未结 5 1890
無奈伤痛
無奈伤痛 2020-12-09 10:16

I have a viewcontroller in that i want to show 3 tableviews(because the content and the table properties are different). How do i add these delegat

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-09 11:07

    You can manage multiple tableView in a single ViewController by writing below code inside UItableViewDelegate and UItableViewDatasource.

    public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if tableView  == tableView1
        {
            // place your code here
        }
        else if tableView  == tableView2 {
            // place your code here
        }
        else {
          return 0
        }
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if tableView  == tableView1
        {
            // place your code here
        }
        else if tableView  == tableView2 {
            // place your code here
        } 
        else {
            return 0
        }
    }
    // You can set a different size of your tableView using below lines of code 
    if tableView  == tableView1{
        return 50
    }
    else{
        return 40
    }
    

提交回复
热议问题