如何在swift中的一个视图控制器上同时显示三个表的值

如何在swift中的一个视图控制器上同时显示三个表的值,swift,uitableview,Swift,Uitableview,在委托的每个函数中,都有一个tableview参数。你可以在这里检查哪张桌子是这样的 class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet var Table1: UITableView! @IBOutlet var Table2: UITableView! func numberOfSectionsInTableView(table

在委托的每个函数中,都有一个
tableview
参数。你可以在这里检查哪张桌子是这样的

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

    @IBOutlet var Table1: UITableView!
    @IBOutlet var Table2: UITableView!

    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
      return 1
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    }
}
错误- UITableView中缺少预期的返回函数

导入UIKit

类ViewController:UIViewController、UITableViewDelegate、UITableViewDataSource{

if tableview == self.Table1
{
   //Your code goes here
}
else if tableview == self.Table2
{
   //Your code goes here
}

您应该更好地解释您的问题,但这可能会有所帮助:您可以有多个tableview,并为每个tableview使用标记,以确定它是哪一个tableview。请添加问题的描述。您有一个错误,可能是因为您的函数有错误。它总是返回一些内容。只需添加“else return 0”或“else return nil”最后ans将是OK,因为答案已消失:您的函数必须在它可以通过的每个路径中返回与其返回类型匹配的值。因此,如果函数未在任何
if/else if
语句中输入或添加
else
语句,则必须设置默认返回值。
@IBOutlet var tbl1: UITableView!
@IBOutlet var tbl2: UITableView!

var tblArry1 = ["Namrata","Shweta","Shraddha"]
var tblArry2 = ["Shahade","Shirbhate","Deshmukh"]

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    if tableView == self.tbl1
    {
        return 1
    }
    else if tableView == self.tbl2
    {
        return 1
    }
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    if tableView == self.tbl1
    {
        return tblArry1.count
    }
    else if tableView == self.tbl2
    {
        return tblArry2.count
    }


}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell = tableView

    if tableView == self.tbl1
    {
        var cell = tableView.dequeueReusableCellWithIdentifier("cell1", forIndexPath: indexPath)
        cell.textLabel?.text = tblArry1[indexPath.row]
        return cell
    } else if tableView == self.tbl2 {
        var cell = tableView.dequeueReusableCellWithIdentifier("cell2", forIndexPath: indexPath)
        cell.textLabel?.text = tblArry2[indexPath.row]
        return cell
    }


}